<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">
<script>
    (function () {
        if ('') {
            if (prompt('请输入文章密码') !== '') {
                alert('密码错误！');
                if (history.length === 1) {
                    location.replace("https://google.com"); // 这里替换成你的首页
                } else {
                    history.back();
                }
            }
        }
    })();
</script>








<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="git,">










<meta name="description" content="linux123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354https://www.itcodemonkey.com/article/12558.html[alvin@VM_0_16_centos ~]$ whoamialvin查看当前登录到服务器的用">
<meta name="keywords" content="git">
<meta property="og:type" content="article">
<meta property="og:title" content="git 笔记">
<meta property="og:url" content="http://yoursite.com/2019/01/08/git-笔记/index.html">
<meta property="og:site_name" content="苏生不惑的博客">
<meta property="og:description" content="linux123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354https://www.itcodemonkey.com/article/12558.html[alvin@VM_0_16_centos ~]$ whoamialvin查看当前登录到服务器的用">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-12-03T07:16:51.857Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="git 笔记">
<meta name="twitter:description" content="linux123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354https://www.itcodemonkey.com/article/12558.html[alvin@VM_0_16_centos ~]$ whoamialvin查看当前登录到服务器的用">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/01/08/git-笔记/">



<meta name="referrer" content="never"> ​​​​


  <title>git 笔记 | 苏生不惑的博客</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">苏生不惑的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/01/08/git-笔记/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">git 笔记</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-01-08T14:39:10+08:00">
                2019-01-08
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  12.4k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  59 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="linux"><a href="#linux" class="headerlink" title="linux"></a>linux</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//www.itcodemonkey.com/article/12558.html</span></span><br><span class="line">[alvin@VM_0_16_centos ~]$ whoami</span><br><span class="line">alvin</span><br><span class="line">查看当前登录到服务器的用户有哪一些。</span><br><span class="line"></span><br><span class="line">[alvin@VM_0_16_centos ~]$ who</span><br><span class="line">alvin    pts/<span class="number">0</span>        <span class="number">2018</span><span class="number">-12</span><span class="number">-09</span> <span class="number">07</span>:<span class="number">25</span> (<span class="number">116.199</span>.***.***)</span><br><span class="line">root     pts/<span class="number">1</span>        <span class="number">2018</span><span class="number">-12</span><span class="number">-09</span> <span class="number">11</span>:<span class="number">05</span> (<span class="number">116.199</span>.***.***)</span><br><span class="line">alvin    pts/<span class="number">2</span>        <span class="number">2018</span><span class="number">-12</span><span class="number">-09</span> <span class="number">11</span>:<span class="number">05</span> (<span class="number">116.199</span>.***.***)</span><br><span class="line">harry    pts/<span class="number">3</span>        <span class="number">2018</span><span class="number">-12</span><span class="number">-09</span> <span class="number">11</span>:<span class="number">06</span> (<span class="number">116.199</span>.***.***)</span><br><span class="line">kate     pts/<span class="number">4</span>        <span class="number">2018</span><span class="number">-12</span><span class="number">-09</span> <span class="number">11</span>:<span class="number">08</span> (<span class="number">116.199</span>.***.***)</span><br><span class="line">alvin    pts/<span class="number">5</span>        <span class="number">2018</span><span class="number">-12</span><span class="number">-09</span> <span class="number">11</span>:<span class="number">53</span> (<span class="number">116.199</span>.***.***)</span><br><span class="line">在显示结果里，第一列是用户名；第二列是连接的终端，tty 表示显示器，pts 表示远程连接；第三列是登陆时间。</span><br><span class="line"></span><br><span class="line">这里信息稍微多一些，但如果我们只想知道谁在线要怎么操作？只需用 users 命令来查看即可。</span><br><span class="line"></span><br><span class="line">[alvin@VM_0_16_centos ~]$ users</span><br><span class="line">alvin alvin alvin harry kate root</span><br><span class="line">显示已经登录系统的用户的名称，以及他们正在做的事</span><br><span class="line">[alvin@VM_0_16_centos ~]$ w</span><br><span class="line"> <span class="number">16</span>:<span class="number">25</span>:<span class="number">54</span> up <span class="number">29</span> days,  <span class="number">6</span>:<span class="number">05</span>,  <span class="number">6</span> users,  load average: <span class="number">0.00</span>, <span class="number">0.01</span>, <span class="number">0.05</span></span><br><span class="line">USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT</span><br><span class="line">alvin    pts/<span class="number">0</span>    <span class="number">116.199</span>.***.**   <span class="number">07</span>:<span class="number">25</span>    <span class="number">2.00</span>s  <span class="number">0.11</span>s  <span class="number">0.00</span>s w</span><br><span class="line">root     pts/<span class="number">1</span>    <span class="number">116.199</span>.***.**   <span class="number">11</span>:<span class="number">05</span>    <span class="number">5</span>:<span class="number">20</span>m  <span class="number">0.02</span>s  <span class="number">0.02</span>s -bash</span><br><span class="line">alvin    pts/<span class="number">2</span>    <span class="number">116.199</span>.***.**   <span class="number">11</span>:<span class="number">05</span>    <span class="number">5</span>:<span class="number">20</span>m  <span class="number">0.04</span>s  <span class="number">0.05</span>s sshd: alvin [priv]</span><br><span class="line">harry    pts/<span class="number">3</span>    <span class="number">116.199</span>.***.**   <span class="number">11</span>:<span class="number">06</span>    <span class="number">4</span>:<span class="number">33</span>m <span class="number">18.08</span>s <span class="number">18.06</span>s watch date</span><br><span class="line">kate     pts/<span class="number">4</span>    <span class="number">116.199</span>.***.**   <span class="number">11</span>:<span class="number">08</span>    <span class="number">4</span>:<span class="number">33</span>m <span class="number">10.51</span>s <span class="number">10.48</span>s top</span><br><span class="line">alvin    pts/<span class="number">5</span>    <span class="number">116.199</span>.***.**   <span class="number">11</span>:<span class="number">53</span>    <span class="number">4</span>:<span class="number">32</span>m  <span class="number">0.02</span>s  <span class="number">0.02</span>s -bash</span><br><span class="line">[alvin@VM_0_16_centos ~]$ w alvin</span><br><span class="line"> <span class="number">16</span>:<span class="number">34</span>:<span class="number">21</span> up <span class="number">29</span> days,  <span class="number">6</span>:<span class="number">14</span>,  <span class="number">6</span> users,  load average: <span class="number">0.00</span>, <span class="number">0.01</span>, <span class="number">0.05</span></span><br><span class="line">USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT</span><br><span class="line">alvin    pts/<span class="number">0</span>    <span class="number">116.199</span>.***.**   <span class="number">07</span>:<span class="number">25</span>    <span class="number">5.00</span>s  <span class="number">0.12</span>s  <span class="number">0.06</span>s sshd: alvin [priv]</span><br><span class="line">alvin    pts/<span class="number">2</span>    <span class="number">116.199</span>.***.**   <span class="number">11</span>:<span class="number">05</span>    <span class="number">5</span>:<span class="number">28</span>m  <span class="number">0.04</span>s  <span class="number">0.05</span>s sshd: alvin [priv]</span><br><span class="line">alvin    pts/<span class="number">5</span>    <span class="number">116.199</span>.***.**   <span class="number">11</span>:<span class="number">53</span>    <span class="number">4</span>:<span class="number">40</span>m  <span class="number">0.02</span>s  <span class="number">0.02</span>s -bash</span><br><span class="line">last命令可用于显示特定用户登录系统的历史记录</span><br><span class="line">[alvin@VM_0_16_centos ~]$ last alvin</span><br><span class="line">alvin    pts/<span class="number">5</span>        <span class="number">116.199</span>.***.**   Sun Dec  <span class="number">9</span> <span class="number">11</span>:<span class="number">53</span>   still logged <span class="keyword">in</span></span><br><span class="line">alvin    pts/<span class="number">2</span>        <span class="number">116.199</span>.***.**   Sun Dec  <span class="number">9</span> <span class="number">11</span>:<span class="number">05</span>   still logged <span class="keyword">in</span></span><br><span class="line">alvin    pts/<span class="number">0</span>        <span class="number">116.199</span>.***.**   Sun Dec  <span class="number">9</span> <span class="number">07</span>:<span class="number">25</span>   still logged <span class="keyword">in</span></span><br><span class="line">alvin    pts/<span class="number">0</span>        <span class="number">116.199</span>.***.**   Sat Dec  <span class="number">8</span> <span class="number">20</span>:<span class="number">42</span> - <span class="number">23</span>:<span class="number">10</span>  (<span class="number">02</span>:<span class="number">28</span>)</span><br><span class="line">alvin    pts/<span class="number">0</span>        <span class="number">119.33</span>.***.**    Mon Dec  <span class="number">3</span> <span class="number">20</span>:<span class="number">50</span> - <span class="number">23</span>:<span class="number">51</span> (<span class="number">1</span>+<span class="number">03</span>:<span class="number">01</span>)</span><br><span class="line">alvin    pts/<span class="number">0</span>        <span class="number">119.33</span>.***.**    Thu Nov <span class="number">29</span> <span class="number">20</span>:<span class="number">20</span> - <span class="number">22</span>:<span class="number">45</span>  (<span class="number">02</span>:<span class="number">24</span>)</span><br><span class="line">alvin    pts/<span class="number">0</span>        <span class="number">223.104</span>.***.**   Thu Nov <span class="number">29</span> <span class="number">06</span>:<span class="number">46</span> - <span class="number">07</span>:<span class="number">00</span>  (<span class="number">00</span>:<span class="number">14</span>)</span><br><span class="line">alvin    pts/<span class="number">0</span>        <span class="number">223.104</span>.***.**   Wed Nov <span class="number">28</span> <span class="number">20</span>:<span class="number">45</span> - <span class="number">22</span>:<span class="number">27</span>  (<span class="number">01</span>:<span class="number">42</span>)</span><br><span class="line">[alvin@VM_0_16_centos ~]$ sudo pkill -kill -t pts/<span class="number">3</span></span><br><span class="line">#harry用户已经被踢除了</span><br><span class="line">[alvin@VM_0_16_centos ~]$ w</span><br><span class="line"> <span class="number">17</span>:<span class="number">04</span>:<span class="number">37</span> up <span class="number">29</span> days,  <span class="number">6</span>:<span class="number">44</span>,  <span class="number">5</span> users,  load average: <span class="number">0.00</span>, <span class="number">0.01</span>, <span class="number">0.05</span></span><br><span class="line">USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT</span><br><span class="line">alvin    pts/<span class="number">0</span>    <span class="number">116.199</span><span class="number">.102</span><span class="number">.65</span>   <span class="number">07</span>:<span class="number">25</span>    <span class="number">5.00</span>s  <span class="number">0.12</span>s  <span class="number">0.00</span>s w</span><br><span class="line">root     pts/<span class="number">1</span>    <span class="number">116.199</span><span class="number">.102</span><span class="number">.65</span>   <span class="number">11</span>:<span class="number">05</span>    <span class="number">5</span>:<span class="number">59</span>m  <span class="number">0.02</span>s  <span class="number">0.02</span>s -bash</span><br><span class="line">alvin    pts/<span class="number">2</span>    <span class="number">116.199</span><span class="number">.102</span><span class="number">.65</span>   <span class="number">11</span>:<span class="number">05</span>    <span class="number">5</span>:<span class="number">59</span>m  <span class="number">0.04</span>s  <span class="number">0.05</span>s sshd: alvin [priv]</span><br><span class="line">kate     pts/<span class="number">4</span>    <span class="number">116.199</span><span class="number">.102</span><span class="number">.65</span>   <span class="number">11</span>:<span class="number">08</span>    <span class="number">5</span>:<span class="number">12</span>m <span class="number">11.94</span>s <span class="number">11.91</span>s top</span><br><span class="line">alvin    pts/<span class="number">5</span>    <span class="number">116.199</span><span class="number">.102</span><span class="number">.65</span>   <span class="number">11</span>:<span class="number">53</span>    <span class="number">5</span>:<span class="number">10</span>m  <span class="number">0.02</span>s  <span class="number">0.02</span>s -bash</span><br></pre></td></tr></table></figure>
<h3 id="回到远程仓库的状态"><a href="#回到远程仓库的状态" class="headerlink" title="回到远程仓库的状态"></a>回到远程仓库的状态</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git fetch --all &amp;&amp; git reset --hard origin/master</span><br></pre></td></tr></table></figure>
<h3 id="重设第一个commit"><a href="#重设第一个commit" class="headerlink" title="重设第一个commit"></a>重设第一个commit</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git update-ref -d HEAD</span><br></pre></td></tr></table></figure>
<h3 id="删除已经合并到master的分支"><a href="#删除已经合并到master的分支" class="headerlink" title="删除已经合并到master的分支"></a>删除已经合并到master的分支</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch --merged master | grep -v <span class="string">'^\*\|  master'</span> | xargs -n <span class="number">1</span> git branch -d</span><br></pre></td></tr></table></figure>
<h3 id="展示本地分支关联远程仓库的情况"><a href="#展示本地分支关联远程仓库的情况" class="headerlink" title="展示本地分支关联远程仓库的情况"></a>展示本地分支关联远程仓库的情况</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git branch -vv</span><br><span class="line">ai_notice      <span class="number">6</span>fa631e7 Merge branch <span class="string">'master'</span> into ai_notice</span><br><span class="line">  delete_msg     <span class="number">33</span>fc3808 Merge branch <span class="string">'master'</span> into delete_msg</span><br></pre></td></tr></table></figure>
<h3 id="关联远程分支"><a href="#关联远程分支" class="headerlink" title="关联远程分支"></a>关联远程分支</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git branch -u origin/mybranch</span><br><span class="line">git push origin/mybranch -u</span><br></pre></td></tr></table></figure>
<h3 id="列出所有远程分支"><a href="#列出所有远程分支" class="headerlink" title="列出所有远程分支"></a>列出所有远程分支</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch -r</span><br></pre></td></tr></table></figure>
<h3 id="列出本地和远程分支"><a href="#列出本地和远程分支" class="headerlink" title="列出本地和远程分支"></a>列出本地和远程分支</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch -a</span><br></pre></td></tr></table></figure>
<h3 id="从远程分支中创建并切换到本地分支"><a href="#从远程分支中创建并切换到本地分支" class="headerlink" title="从远程分支中创建并切换到本地分支"></a>从远程分支中创建并切换到本地分支</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -b &lt;branch-name&gt; origin/&lt;branch-name&gt;</span><br></pre></td></tr></table></figure>
<h3 id="删除远程分支"><a href="#删除远程分支" class="headerlink" title="删除远程分支"></a>删除远程分支</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git push origin --<span class="keyword">delete</span> &lt;remote-branchname&gt;</span><br><span class="line">或者</span><br><span class="line"></span><br><span class="line">git push origin :&lt;remote-branchname&gt;</span><br></pre></td></tr></table></figure>
<h3 id="重命名本地分支"><a href="#重命名本地分支" class="headerlink" title="重命名本地分支"></a>重命名本地分支</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch -m &lt;<span class="keyword">new</span>-branch-name&gt;</span><br></pre></td></tr></table></figure>
<h3 id="切回到某个标签"><a href="#切回到某个标签" class="headerlink" title="切回到某个标签"></a>切回到某个标签</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -b branch_name tag_name</span><br></pre></td></tr></table></figure>
<h3 id="放弃工作区的修改"><a href="#放弃工作区的修改" class="headerlink" title="放弃工作区的修改"></a>放弃工作区的修改</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git checkout &lt;file-name&gt;</span><br><span class="line">放弃所有修改：</span><br><span class="line"></span><br><span class="line">git checkout .</span><br></pre></td></tr></table></figure>
<h3 id="修改远程仓库的url"><a href="#修改远程仓库的url" class="headerlink" title="修改远程仓库的url"></a>修改远程仓库的url</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git remote set-url origin &lt;URL&gt;</span><br></pre></td></tr></table></figure>
<h3 id="查看两个星期内的改动"><a href="#查看两个星期内的改动" class="headerlink" title="查看两个星期内的改动"></a>查看两个星期内的改动</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git whatchanged --since=<span class="string">'2 weeks ago'</span></span><br></pre></td></tr></table></figure>
<h3 id="展示简化的commit历史"><a href="#展示简化的commit历史" class="headerlink" title="展示简化的commit历史"></a>展示简化的commit历史</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log --pretty=oneline --graph --decorate --all</span><br></pre></td></tr></table></figure>
<h3 id="展示任意分支某一文件的内容"><a href="#展示任意分支某一文件的内容" class="headerlink" title="展示任意分支某一文件的内容"></a>展示任意分支某一文件的内容</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git show &lt;branch-name&gt;:&lt;file-name&gt;</span><br></pre></td></tr></table></figure>
<h3 id="clone下来指定的单一分支"><a href="#clone下来指定的单一分支" class="headerlink" title="clone下来指定的单一分支"></a>clone下来指定的单一分支</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone -b &lt;branch-name&gt; --single-branch https:<span class="comment">//github.com/user/repo.git</span></span><br></pre></td></tr></table></figure>
<h3 id="忽略某个文件的改动"><a href="#忽略某个文件的改动" class="headerlink" title="忽略某个文件的改动"></a>忽略某个文件的改动</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">关闭 track 指定文件的改动，也就是 Git 将不会在记录这个文件的改动</span><br><span class="line"></span><br><span class="line">git update-index --assume-unchanged path/to/file</span><br><span class="line">恢复 track 指定文件的改动</span><br><span class="line"></span><br><span class="line">git update-index --no-assume-unchanged path/to/file</span><br></pre></td></tr></table></figure>
<h3 id="在commit-log中查找相关内容"><a href="#在commit-log中查找相关内容" class="headerlink" title="在commit log中查找相关内容"></a>在commit log中查找相关内容</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log --all --grep=<span class="string">'&lt;given-text&gt;'</span></span><br></pre></td></tr></table></figure>
<h3 id="搭建Git服务器"><a href="#搭建Git服务器" class="headerlink" title="搭建Git服务器"></a>搭建Git服务器</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//coffeephp.com/articles/3</span></span><br><span class="line">$ sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel</span><br><span class="line">$ sudo yum install git</span><br><span class="line">$ sudo adduser git</span><br><span class="line">$ cd /home/git</span><br><span class="line">$ mkdir .ssh &amp;&amp; chmod <span class="number">700</span> .ssh</span><br><span class="line">$ touch .ssh/authorized_keys &amp;&amp; chmod <span class="number">600</span> .ssh/authorized_keys</span><br><span class="line">$ sudo chown -R git:git .ssh</span><br><span class="line"></span><br><span class="line">客户端上生成密钥#</span><br><span class="line"></span><br><span class="line">$ cd ~</span><br><span class="line">$ ssh-keygen -t rsa</span><br><span class="line"> $ scp ~<span class="regexp">/.ssh/i</span>d_rsa.pub root@server_ip:<span class="regexp">/home/gi</span>t/.ssh/authorized_keys</span><br><span class="line"> </span><br><span class="line"> $ mkdir /home/git/repo/</span><br><span class="line"> $ sudo chown git:git /home/git/repo/</span><br><span class="line"> $ cd /home/git/repo/</span><br><span class="line"> $ sudo git init --bare sample.git</span><br><span class="line"> $ sudo chown -R git:git sample.git</span><br><span class="line"> </span><br><span class="line"> $ git clone git@<span class="number">118.24</span><span class="number">.158</span><span class="number">.116</span>/:<span class="regexp">/home/gi</span>t/repo/sample.git sample </span><br><span class="line"> $cd sample</span><br><span class="line"> $ touch index.html</span><br><span class="line"> $ git add index.html</span><br><span class="line"> $ git commit index.html -m <span class="string">'first commit'</span></span><br><span class="line"> $ git push origin master</span><br><span class="line"> Enumerating objects: <span class="number">3</span>, done.</span><br><span class="line"> Counting objects: <span class="number">100</span>% (<span class="number">3</span>/<span class="number">3</span>), done.</span><br><span class="line"> Writing objects: <span class="number">100</span>% (<span class="number">3</span>/<span class="number">3</span>), <span class="number">209</span> bytes | <span class="number">209.00</span> KiB/s, done.</span><br><span class="line"> Total <span class="number">3</span> (delta <span class="number">0</span>), reused <span class="number">0</span> (delta <span class="number">0</span>)</span><br><span class="line"> To <span class="number">118.24</span><span class="number">.158</span><span class="number">.116</span>:<span class="regexp">/home/gi</span>t/repo/sample.git</span><br><span class="line">  * [<span class="keyword">new</span> branch]      master -&gt; master</span><br><span class="line">创建网站的目录#</span><br><span class="line"></span><br><span class="line">$ sudo mkdir /<span class="keyword">var</span>/www/sample -p</span><br><span class="line">$ sudo chown -R git:git /<span class="keyword">var</span>/www/sample</span><br><span class="line"></span><br><span class="line">设置git钩子#</span><br><span class="line"></span><br><span class="line">$ cd /home/git/repo/sample.git/hooks</span><br><span class="line">$ sudo vim post-receive</span><br><span class="line"></span><br><span class="line">写入以下内容：</span><br><span class="line"></span><br><span class="line"><span class="meta">#!/bin/sh</span></span><br><span class="line">GIT_WORK_TREE=<span class="regexp">/var/</span>www/sample git checkout -f</span><br><span class="line"></span><br><span class="line">写入权限</span><br><span class="line"></span><br><span class="line">$ sudo chmod +x post-receive</span><br><span class="line"></span><br><span class="line">[root@VM_0_14_centos hooks]# ll /var/www/sample/</span><br><span class="line">total <span class="number">4</span></span><br><span class="line">-rw-rw-r-- <span class="number">1</span> git git <span class="number">5</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">23</span> index.html</span><br><span class="line"></span><br><span class="line">$ ssh git@<span class="number">118.24</span><span class="number">.158</span><span class="number">.116</span></span><br><span class="line">Last failed login: Wed Jan  <span class="number">9</span> <span class="number">09</span>:<span class="number">38</span>:<span class="number">59</span> CST <span class="number">2019</span> <span class="keyword">from</span> <span class="number">219.246</span><span class="number">.78</span><span class="number">.17</span> on ssh:notty</span><br><span class="line">There were <span class="number">264</span> failed login attempts since the last successful login.</span><br><span class="line">[git@VM_0_14_centos ~]$ ll</span><br><span class="line">total <span class="number">4</span></span><br><span class="line">drwxr-xr-x <span class="number">3</span> git git <span class="number">4096</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">16</span> repo</span><br><span class="line">[git@VM_0_14_centos ~]$ ll repo/</span><br><span class="line">total <span class="number">4</span></span><br><span class="line">drwxr-xr-x <span class="number">7</span> git git <span class="number">4096</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">23</span> sample.git</span><br><span class="line">[git@VM_0_14_centos ~]$ ll repo/sample.git/</span><br><span class="line">total <span class="number">36</span></span><br><span class="line">drwxr-xr-x  <span class="number">2</span> git git <span class="number">4096</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">16</span> branches</span><br><span class="line">-rw-r--r--  <span class="number">1</span> git git   <span class="number">66</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">16</span> config</span><br><span class="line">-rw-r--r--  <span class="number">1</span> git git   <span class="number">73</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">16</span> description</span><br><span class="line">-rw-r--r--  <span class="number">1</span> git git   <span class="number">23</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">16</span> HEAD</span><br><span class="line">drwxr-xr-x  <span class="number">2</span> git git <span class="number">4096</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">21</span> hooks</span><br><span class="line">-rw-rw-r--  <span class="number">1</span> git git  <span class="number">112</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">23</span> index</span><br><span class="line">drwxr-xr-x  <span class="number">2</span> git git <span class="number">4096</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">16</span> info</span><br><span class="line">drwxr-xr-x <span class="number">10</span> git git <span class="number">4096</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">23</span> objects</span><br><span class="line">drwxr-xr-x  <span class="number">4</span> git git <span class="number">4096</span> Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">16</span> refs</span><br><span class="line"></span><br><span class="line">[root@VM_0_14_centos hooks]# cat /etc/shells</span><br><span class="line">/bin/sh</span><br><span class="line">/bin/bash</span><br><span class="line">/sbin/nologin</span><br><span class="line">/usr/bin/sh</span><br><span class="line">/usr/bin/bash</span><br><span class="line">/usr/sbin/nologin</span><br><span class="line">/bin/tcsh</span><br><span class="line">/bin/csh</span><br><span class="line">/usr/bin/fish</span><br><span class="line">$ which git-shell   # make sure git-shell is installed on your system.</span><br><span class="line">/usr/bin/git-shell</span><br><span class="line">$ sudo vim /etc/shells  # and add the path to git-shell from last command</span><br><span class="line"></span><br><span class="line">使用 chsh 命令修改任一系统用户的 shell</span><br><span class="line"></span><br><span class="line">$ sudo chsh git  # and enter the path to git-shell, usually: /usr/bin/git-shell</span><br><span class="line">Changing shell <span class="keyword">for</span> git.</span><br><span class="line">New shell [<span class="regexp">/bin/</span>bash]: <span class="regexp">/usr/</span>bin/git-shell</span><br><span class="line">Shell changed.</span><br><span class="line">这样，用户 git 就只能利用 SSH 连接对 Git 仓库进行推送和拉取操作，而不能登录机器并取得普通 shell。 如果试图登录，你会发现尝试被拒绝，像这样：</span><br><span class="line"></span><br><span class="line">$ ssh git@<span class="number">118.24</span><span class="number">.158</span><span class="number">.116</span></span><br><span class="line">Last login: Wed Jan  <span class="number">9</span> <span class="number">14</span>:<span class="number">29</span>:<span class="number">56</span> <span class="number">2019</span> <span class="keyword">from</span> <span class="number">218.30</span><span class="number">.113</span><span class="number">.34</span></span><br><span class="line">fatal: Interactive git shell is not enabled.</span><br><span class="line">hint: ~<span class="regexp">/git-shell-commands should exist and have read and execute access.</span></span><br><span class="line"><span class="regexp">Connection to 118.24.158.116 closed.</span></span><br></pre></td></tr></table></figure>
<h3 id="查看定时任务日志"><a href="#查看定时任务日志" class="headerlink" title="查看定时任务日志"></a>查看定时任务日志</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">默认位于 /<span class="keyword">var</span>/log/cron 文件：</span><br><span class="line"></span><br><span class="line">tail -f /<span class="keyword">var</span>/log/cron</span><br><span class="line">cat /<span class="keyword">var</span>/log/cron | grep <span class="string">"sh"</span></span><br></pre></td></tr></table></figure>
<h3 id="GitHub-API-limit"><a href="#GitHub-API-limit" class="headerlink" title="GitHub API limit"></a>GitHub API limit</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">GitHub API limit (<span class="number">0</span> calls/hr) is exhausted, could not fetch https:<span class="comment">//api.github.com/graphql. Create a GitHub OAuth token to go over the API rate limit. You can also wait until 2019-01-25 09:36:32 for the rate limit to reset.</span></span><br><span class="line"></span><br><span class="line">Head to https:<span class="comment">//github.com/settings/tokens/new?scopes=repo&amp;description=Composer+on+BJ-D-212361A+2019-01-25+0835</span></span><br><span class="line">to retrieve a token. It will be stored <span class="keyword">in</span> <span class="string">"C:/Users/xxx/AppData/Roaming/Composer/auth.json"</span> <span class="keyword">for</span> future use by Composer.</span><br><span class="line">Token (hidden):</span><br></pre></td></tr></table></figure>
<h3 id="在Git中添加忽略文件"><a href="#在Git中添加忽略文件" class="headerlink" title="在Git中添加忽略文件"></a>在Git中添加忽略文件</h3><p>如果文件已经添加到缓存区了<br>// 移除file1<br>git reset HEAD file1<br>// 移除全部<a href="https://blog.tedxiong.com/add_ingore_file_for_git.html" target="_blank" rel="noopener">https://blog.tedxiong.com/add_ingore_file_for_git.html</a><br>git reset HEAD *<br>//如果有多个文件可以使用通配符<br>git rm –cached FILENAME<br>添加忽略文件<br>touch .gitignore<br>echo ‘file1’ &gt;&gt; .gitignore<br>echo ‘build/‘ &gt;&gt; .gitignore<br>配置全局的忽略文件<br>git config –global core.excludesfile ~/.gitignore_global<br>添加例外<br>如果不想跟别人分享.gitignore文件，可以在.git/info/exclude中配置规则。</p>
<h3 id="一键提交脚本"><a href="#一键提交脚本" class="headerlink" title="一键提交脚本"></a>一键提交脚本</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">vi push.sh</span><br><span class="line">time=<span class="string">`date "+%Y-%m-%d_%H-%M-%S"`</span></span><br><span class="line">who=<span class="string">`hostname'</span></span><br><span class="line"><span class="string">git add --all</span></span><br><span class="line"><span class="string">git commit -m "<span class="subst">$&#123;who&#125;</span> push @ <span class="subst">$&#123;time&#125;</span>"</span></span><br><span class="line"><span class="string">git push origin master</span></span><br><span class="line"><span class="string">echo "Finished Push"</span></span><br></pre></td></tr></table></figure>
<h3 id="免密登录"><a href="#免密登录" class="headerlink" title="免密登录"></a>免密登录</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa</span><br><span class="line">ssh-copy-id -i/Users/USERNAME/.ssh/id_rsa.pub root@ip</span><br><span class="line">touch authorized_keys</span><br><span class="line">chmod <span class="number">600</span> /root/.ssh/authorized_keys</span><br><span class="line">cat /root/.ssh/id_rsa.pub &gt;&gt; <span class="regexp">/root/</span>.ssh/authorized_keys</span><br><span class="line">ssh root@ip</span><br><span class="line">如果此时想让其他人也免密登录 可以把本地的id_rsa 文件拷贝给别人 执行命令</span><br><span class="line"></span><br><span class="line">ssh -i id_rsa root@ip </span><br><span class="line"> vim /etc/ssh/sshd_config</span><br><span class="line">RSAAuthentication yes</span><br><span class="line">PubkeyAuthentication yes</span><br><span class="line">AuthorizedKeysFile %h/.ssh/authorized_keys</span><br><span class="line">PasswordAuthentication no #修改之前一定要确认你的秘钥可以正常使用</span><br><span class="line">重启ssh配置生效</span><br><span class="line"></span><br><span class="line">service sshd restart</span><br><span class="line">从服务器下载</span><br><span class="line"></span><br><span class="line">[username@host ~]$ cd ~<span class="regexp">/.ssh</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">[username@host ~]$ ssh-keygen /</span><span class="regexp">/ 一路回车</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">[username@host ~]$ cat id_rsa.pub &gt;&gt; authorized_keys</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">[username@host ~]$ chmod 600 authorized_keys</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">[username@host ~]$ chmod 700 ~/</span>.ssh</span><br><span class="line"><span class="comment">// 下载私钥</span></span><br><span class="line"></span><br><span class="line">[local@host ~]$ sudo scp -i USERNAME@HOST /usr/USERNAME/.ssh/id_rsa /LOCAL_PATH/id_rsa</span><br><span class="line"></span><br><span class="line"><span class="comment">// 测试秘钥登录</span></span><br><span class="line"></span><br><span class="line">sudo ssh USERNAME@HOST -i /LOCAL_PATH/id_rsa</span><br></pre></td></tr></table></figure>
<h3 id="最近24小时修改过的文件"><a href="#最近24小时修改过的文件" class="headerlink" title="最近24小时修改过的文件"></a>最近24小时修改过的文件</h3><p>find / -mtime -1</p>
<h3 id="修改-hostname"><a href="#修改-hostname" class="headerlink" title="修改 hostname"></a>修改 hostname</h3><p>hostname syyong # 临时修改 hostname 为 syyong<br>vi /etc/sysconfig/network –&gt; HOSTNAME = syyong # 永久修改 hostname 为syyong</p>
<h3 id="查找文件"><a href="#查找文件" class="headerlink" title="查找文件"></a>查找文件</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">find /etc/ -name httpd.conf # 在 /etc 目录下查找文件名为 httpd.conf</span><br><span class="line">find /etc/ -name http* # 在 /etc目录下以 httpd 开头的文件</span><br><span class="line">find /root/ -size +10M # 在 /root 目录下大于 10M 的文件</span><br><span class="line">find /home/ -user syyong # 在 /home 目录下查找所有者是 syyong</span><br><span class="line">find ./ -user syyong -exec rm -rf&#123;&#125;\ # 在当前目录下把找到所有者是 syyong 的用户的文件删除掉</span><br><span class="line">find /etc -cmin -5 # 在 /etc 目录下查找5分钟内修改过属性的文件和目录</span><br><span class="line">find /etc -size +163840 -a -size -204800 # 在 /etc 目录下查找大于 80M 小于 100M 的文件</span><br><span class="line">find .|xargs grep -ri "lnmp" # 在当前目录下查找含 lnmp 字符的文件</span><br></pre></td></tr></table></figure>
<h3 id="ssh"><a href="#ssh" class="headerlink" title="ssh"></a>ssh</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ssh -p 22 syyong@192.168.1.2 # 通过 ssh 通过账号密码登录到 192.168.1.2 服务器</span><br><span class="line">ssh -i ./ssh-key.pem syyong@192.168.1.2 # 通过 ssh 通过证书登录到 192.168.1.2 服务器</span><br></pre></td></tr></table></figure>
<h3 id="scp"><a href="#scp" class="headerlink" title="scp"></a>scp</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">scp -p 2202 /home/lnmp.tar.gz www@192.168.1.2:/home/ # 将文件 lnmp.tar.gz 同步到 192.168.1.2 服务器的 /home/ 目录下</span><br><span class="line">rsync -avzP /home/lnmp.tar.gz -e 'ssh -p 2202' www@192.168.1.2:/home/ # 将文件 lnmp.tar.gz 增量同步到 192.168.1.2 服务器的 /home/ 目录下</span><br><span class="line">touch file&#123;1..100&#125; # 批量创建 file1,file2...file100</span><br><span class="line">touch file&#123;a..z&#125; # 批量创建 filea,fileb...filez</span><br><span class="line">touch file&#123;A..Z&#125; # 批量创建 fileA,fileB...fileZ</span><br><span class="line">echo 'lnmp' &gt; lnmp.txt # 覆盖式写入 lnmp 到 lnmp.txt 文件中</span><br><span class="line">echo 'lnmp' &gt;&gt; lnmp.txt # 追加式写入 lnmp 到 lnmp.txt 文件中</span><br><span class="line"></span><br><span class="line">tar -xzvf syyong.tar.gz # 解压 gz 文件</span><br><span class="line">unzip syyong.zip -d /home # 解压 zip 文件到 /home 目录下</span><br><span class="line">tar -czvf syyong syyong.tar.gz # 将文件压缩成 gz 文件</span><br><span class="line">zip -r syyong.zip syyong # 压缩 syyong 目录为 zip 文件</span><br><span class="line">pkill php-fpm # 杀掉所有 php-fpm 进程</span><br><span class="line">killall php-fpm # 杀掉所有 php-fpm 进程</span><br><span class="line">netstat -tunpl|grep 80 # 查看端口使用情况</span><br><span class="line">tcpdump -i eth0  # 监听eth0网卡数据</span><br><span class="line">rpm -q xxx # 查看 xxx 软件是否已安装</span><br><span class="line">rpm -qa # 查看已安装了的所有的 rpm 包</span><br><span class="line">rpm -ivh  /home/xxx.rpm # 按路径安装 xxx.rpm 软件包并显示进度</span><br><span class="line">rpm -e xxx.rpm # 删除 xxx rpm 包</span><br><span class="line">yum install xxx # 安装 xxx 软件</span><br><span class="line">yum search xxx # 在 yum 仓库中查找 xxx 软件</span><br><span class="line">yum remove xxx # 卸载 xxx 软件</span><br><span class="line">init 0 # 关机</span><br><span class="line">init 1 # 进入单用户模式</span><br><span class="line">init 5 # 进入图形化登录界面 </span><br><span class="line">init 6 # 重启</span><br><span class="line">nohup php index.php # 以 nohup 方式运行 index.php 脚本，这样关闭终端操作不影响程序的继续运行</span><br><span class="line">time php index.php # 统计显示执行 index.php 脚本耗时情况</span><br><span class="line">curl -o /dev/null -s -w %&#123;time_namelookup&#125;::%&#123;time_connect&#125;::%&#123;time_starttransfer&#125;::%&#123;time_total&#125;::%&#123;speed_download&#125;"\n" "http://www.syyong.com" # 查看访问站点的 rt</span><br><span class="line">grep -&gt; 过滤</span><br><span class="line">cut -&gt; 切割，从一个文本文件或者文本流中提取文本列</span><br><span class="line">sort -&gt; 命令对 File 参数指定的文件中的行排序，并将结果写到标准输出</span><br><span class="line">xargs -&gt; 读入 stdin 的数据，并且以空格符或断行字符作为分辨，将 stdin 的数据分隔成为 <span class="built_in">arguments</span></span><br><span class="line">uniq -&gt; 去除重复行</span><br><span class="line">wc -&gt; 统计文件里面有多少单词，多少行，多少字符</span><br><span class="line">awk '&#123;print $0&#125;' 2016.log # 输出 2016.log 的每行数据</span><br><span class="line">awk '!arr[$1]++' 2016.log |wc -l # 统计 2016.log 中不重复的行的个数</span><br><span class="line">rz -bye # 会弹出文件窗口，选择本地要上传的文件即可上传</span><br><span class="line">sz file1 file2 # 下载 file1、file2 文件到本地</span><br><span class="line">yum install lrzsz # 安装 lrzsz 软件</span><br></pre></td></tr></table></figure>
<h3 id="netstat-命令查看连接数判断攻击"><a href="#netstat-命令查看连接数判断攻击" class="headerlink" title="netstat 命令查看连接数判断攻击"></a>netstat 命令查看连接数判断攻击</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">显示所有活动的网络连接。</span><br><span class="line"></span><br><span class="line">#netstat -na</span><br><span class="line">查看同时连接到哪个服务器IP比较多，cc攻击用。使用双网卡或多网卡可用。</span><br><span class="line"></span><br><span class="line"># netstat -an|awk  '&#123;print $4&#125;'|sort|uniq -c|sort -nr|head</span><br><span class="line">查看哪些IP连接到服务器连接多，可以查看连接异常IP。</span><br><span class="line"></span><br><span class="line">#netstat -an|awk -F: '&#123;print $2&#125;'|sort|uniq -c|sort -nr|head</span><br><span class="line">显示所有<span class="number">80</span>端口的网络连接并排序。这里的<span class="number">80</span>端口是http端口，所以可以用来监控web服务。如果看到同一个IP有大量连接的话就可以判定单点流量攻击了。</span><br><span class="line"></span><br><span class="line">#netstat -an | grep :80 | sort    </span><br><span class="line">这个命令可以查找出当前服务器有多少个活动的 SYNC_REC 连接。正常来说这个值很小，最好小于<span class="number">5</span>。 当有Dos攻击或的时候，这个值相当的高。但是有些并发很高的服务器，这个值确实是很高，因此很高并不能说明一定被攻击。</span><br><span class="line"></span><br><span class="line">#netstat -n -p|grep SYN_REC | wc -l   </span><br><span class="line">列出所有连接过的IP地址。</span><br><span class="line"></span><br><span class="line">#netstat -n -p | grep SYN_REC | sort -u   </span><br><span class="line">列出所有发送SYN_REC连接节点的IP地址。</span><br><span class="line"></span><br><span class="line">#netstat -n -p | grep SYN_REC | awk '&#123;print $5&#125;' | awk -F: '&#123;print $1&#125;'</span><br><span class="line">使用netstat命令计算每个主机连接到本机的连接数。</span><br><span class="line"></span><br><span class="line">#netstat -ntu | awk '&#123;print $5&#125;' | cut -d: -f1 | sort | uniq -c | sort -n </span><br><span class="line">列出所有连接到本机的UDP或者TCP连接的IP数量。</span><br><span class="line"></span><br><span class="line">#netstat -anp |grep 'tcp|udp' | awk '&#123;print $5&#125;' | cut -d: -f1 | sort | uniq -c | sort -n  </span><br><span class="line">检查 ESTABLISHED 连接并且列出每个IP地址的连接数量。</span><br><span class="line"></span><br><span class="line">#netstat -ntu | grep ESTAB | awk '&#123;print $5&#125;' | cut -d: -f1 | sort | uniq -c | sort -nr </span><br><span class="line">列出所有连接到本机<span class="number">80</span>端口的IP地址和其连接数。<span class="number">80</span>端口一般是用来处理HTTP网页请求。</span><br><span class="line"></span><br><span class="line">#netstat -plan|grep :80|awk &#123;'print $5'&#125;|cut -d: -f 1|sort|uniq -c|sort -nk 1  </span><br><span class="line">显示连接<span class="number">80</span> 端口前<span class="number">10</span>的ip，并显示每个IP的连接数。这里的<span class="number">80</span>端口是http端口，所以可以用来监控web服务。如果看到同一个IP有大量连接的话就可以判定单点流量攻击了。</span><br><span class="line">#netstat -antp | awk '$4 ~ /:80$/ &#123;print $4" "$5&#125;' | awk '&#123;print $2&#125;'|awk -F : &#123;'print $1'&#125; | uniq -c | sort -nr | head -n 10</span><br></pre></td></tr></table></figure>
<h3 id="Linux-相关信息"><a href="#Linux-相关信息" class="headerlink" title="Linux 相关信息"></a>Linux 相关信息</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">lsb_release -a              # 查看操作系统版本https://liam.page/2016/11/06/Linux-Info-Cheatsheet/</span><br><span class="line">head -n 1 /etc/issue        # 查看操作系统版本</span><br><span class="line">cat /proc/version           # 查看操作系统内核信息</span><br><span class="line">uname -a                    # 查看操作系统内核信息、CPU 信息</span><br><span class="line">cat /proc/cpuinfo           # 查看 CPU 信息</span><br><span class="line">hostname                    # 查看计算机名字</span><br><span class="line">env                         # 列出环境变量</span><br><span class="line">lsmod                       # 列出加载的内核模块</span><br><span class="line">uptime                      # 查看系统运行时间、负载、用户数量</span><br><span class="line">cat /proc/loadavg           # 查看系统负载</span><br><span class="line">free -m                     # 查看物理内存和交换区的使用情况</span><br><span class="line">grep MemTotal /proc/meminfo # 查看内存总量</span><br><span class="line">grep MemFree /proc/meminfo  # 查看空闲内存总量</span><br><span class="line">df -h                       # 查看各分区使用情况</span><br><span class="line">fdisk -l                    # 查看所有分区</span><br><span class="line">swapon -s                   # 查看所有交换分区</span><br><span class="line">hdparm -i /dev/hda          # 查看 IDE 磁盘的参数</span><br><span class="line">dmesg | grep IDE            # 查看系统启动时 IDE 磁盘的状态</span><br><span class="line">mount | column -t           # 查看各分区的挂载状态</span><br><span class="line">du -sh &lt;目录名&gt;              # 查看指定目录的大小</span><br><span class="line">ifconfig                    # 查看所有网络接口的属性</span><br><span class="line">iptables -L                 # 查看 iptables 防火墙</span><br><span class="line">route -n                    # 查看本机路由表</span><br><span class="line">netstat -lntp               # 查看所有监听端口</span><br><span class="line">netstat -antp               # 查看所有已建立的连接</span><br><span class="line">netstat -s                  # 查看网络统计信息</span><br><span class="line">w                           # 查看活动用户以及他们在做什么</span><br><span class="line">who                         # 查看活动用户</span><br><span class="line">id &lt;用户名&gt;                  # 查看用户的 ID、组信息</span><br><span class="line">cut -d: -f1 /etc/passwd     # 查看系统中所有用户</span><br><span class="line">cut -d: -f1 /etc/group      # 查看系统所有组</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">cat &lt;filename&gt; | sort | uniq -d     # 只显示重复的行，每行只显示一次  交集</span><br><span class="line">cat &lt;filename&gt; | sort | uniq -D     # 只显示重复的行</span><br><span class="line">cat &lt;filename&gt; | sort | uniq -i     # 忽略大小写</span><br><span class="line">cat &lt;filename&gt; | sort | uniq -u     # 只显示只出现一次的行</span><br><span class="line">cat &lt;filename&gt; | sort | uniq -c     # 统计每行重复的次数</span><br><span class="line">sort &lt;file1&gt; &lt;file2&gt; &lt;file2&gt; | uniq -u  # 差集</span><br><span class="line">sort &lt;file1&gt; &lt;file2&gt; | uniq -u  # 对称差集</span><br><span class="line">https://liam.page/2016/05/05/best-match-using-sort-and-uniq-to-do-set-operations/</span><br><span class="line">sort &lt;file1&gt; &lt;file2&gt; | uniq -d      # 交集</span><br><span class="line">sort &lt;file1&gt; &lt;file2&gt; | uniq         # 并集</span><br></pre></td></tr></table></figure>
<h3 id="反向代理以访问-Gist"><a href="#反向代理以访问-Gist" class="headerlink" title="反向代理以访问 Gist"></a>反向代理以访问 Gist</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">server &#123;</span><br><span class="line">    listen  <span class="number">80</span>;</span><br><span class="line">    server_name gist.example.com;</span><br><span class="line">    access_log  off;</span><br><span class="line">    resolver    <span class="number">8.8</span><span class="number">.8</span><span class="number">.8</span>;</span><br><span class="line">    location / &#123;</span><br><span class="line">        proxy_pass          https:<span class="comment">//gist.github.com;</span></span><br><span class="line">        proxy_cache_valid   <span class="number">200</span> <span class="number">302</span> <span class="number">1</span>h;</span><br><span class="line">        proxy_cache_valid   <span class="number">404</span> <span class="number">1</span>m;</span><br><span class="line">        proxy_cache_use_stale error timeout invalid_header updating</span><br><span class="line">            http_500 http_502 http_503 http_504;</span><br><span class="line">        proxy_set_header    Accept-Encoding <span class="string">""</span>;</span><br><span class="line">        proxy_set_header    Accept-Language <span class="string">"zh-CN"</span>;</span><br><span class="line">        proxy_set_header    User-Agent $http_user_agent;</span><br><span class="line">        sub_filter  https:<span class="comment">//gist-assets.github.com/ http://gist.example.com;</span></span><br><span class="line">        sub_filter  https:<span class="comment">//gist.github.com/ http://gist.example.com;</span></span><br><span class="line">        sub_filter_once     off;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">访问 http:<span class="comment">//gist.example.com 就相当于访问了 https://gist.github.com。https://liam.page/2015/09/07/reverse-proxy-to-get-access-to-gist/</span></span><br></pre></td></tr></table></figure>
<h3 id="文件名大小写有问题"><a href="#文件名大小写有问题" class="headerlink" title="文件名大小写有问题"></a>文件名大小写有问题</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">方案一：</span><br><span class="line"></span><br><span class="line">删除旧文件，提交代码。</span><br><span class="line">添加新文件，提交代码。</span><br><span class="line">方案二：修改配置</span><br><span class="line"></span><br><span class="line">git config core.ignorecase <span class="literal">false</span></span><br><span class="line">方案三：</span><br><span class="line"></span><br><span class="line">$ git mv test.txt tmp.txt</span><br><span class="line">$ git mv tmp.txt Test.txt</span><br><span class="line">$ git commit -m <span class="string">"Renamed test.txt to Test.txt"</span></span><br><span class="line"></span><br><span class="line">找出请求次数最多的前<span class="number">50</span>个IP：</span><br><span class="line"></span><br><span class="line">awk <span class="string">'&#123;print $1&#125;'</span> /path/to/web-server-log/access.log | sort|uniq -c | sort -nr | head -n <span class="number">50</span></span><br></pre></td></tr></table></figure>
<h3 id="paste-命令支持输入多个文件"><a href="#paste-命令支持输入多个文件" class="headerlink" title="paste 命令支持输入多个文件"></a>paste 命令支持输入多个文件</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">$ paste -d <span class="string">'|'</span> paste2.txt paste1.txt paste3.txt</span><br><span class="line">a|<span class="number">1</span>|A</span><br><span class="line">b|<span class="number">2</span>|B</span><br><span class="line">c|<span class="number">3</span>|C</span><br><span class="line">$ who</span><br><span class="line">Liam :<span class="number">0</span>           <span class="number">2016</span><span class="number">-11</span><span class="number">-08</span> <span class="number">00</span>:<span class="number">07</span></span><br><span class="line">Liam pts/<span class="number">0</span>        <span class="number">2016</span><span class="number">-11</span><span class="number">-08</span> <span class="number">00</span>:<span class="number">23</span> (:<span class="number">0.0</span>)</span><br><span class="line">Liam pts/<span class="number">1</span>        <span class="number">2016</span><span class="number">-11</span><span class="number">-08</span> <span class="number">00</span>:<span class="number">15</span> (:<span class="number">0.0</span>)</span><br><span class="line">$ who | tr -s <span class="string">' '</span></span><br><span class="line">Liam :<span class="number">0</span> <span class="number">2016</span><span class="number">-11</span><span class="number">-08</span> <span class="number">00</span>:<span class="number">07</span></span><br><span class="line">Liam pts/<span class="number">0</span> <span class="number">2016</span><span class="number">-11</span><span class="number">-08</span> <span class="number">00</span>:<span class="number">23</span> (:<span class="number">0.0</span>)</span><br><span class="line">Liam pts/<span class="number">1</span> <span class="number">2016</span><span class="number">-11</span><span class="number">-08</span> <span class="number">00</span>:<span class="number">15</span> (:<span class="number">0.0</span>)</span><br><span class="line">使用 -s 参数，可以逐行地将连续的字符 unique 成单独的一个字符。</span><br><span class="line">$ who | tr -s <span class="string">' '</span> | cut -d <span class="string">' '</span> -f <span class="number">1</span>,<span class="number">3</span>,<span class="number">4</span></span><br><span class="line">Liam <span class="number">2016</span><span class="number">-11</span><span class="number">-08</span> <span class="number">00</span>:<span class="number">07</span></span><br><span class="line">Liam <span class="number">2016</span><span class="number">-11</span><span class="number">-08</span> <span class="number">00</span>:<span class="number">23</span></span><br><span class="line">Liam <span class="number">2016</span><span class="number">-11</span><span class="number">-08</span> <span class="number">00</span>:<span class="number">15</span></span><br></pre></td></tr></table></figure>
<h3 id="Git-webhook"><a href="#Git-webhook" class="headerlink" title="Git webhook"></a>Git webhook</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//http://blog.text.wiki/2017/10/31/git-webhooks-for-php.html</span></span><br><span class="line">设置用于接收请求的 URL。</span><br><span class="line">服务器收到 push、pull request、merge、tag 等操作时，会将相应信息发送给步骤 <span class="number">1</span> 里的 URL。</span><br><span class="line">URL 对应的程序收到网络请求后，执行自动部署、邮件通知等操作。</span><br><span class="line"></span><br><span class="line">部署 SSH 无密码登录 GitHub 为例，在 Settings -&gt; Deploy keys，选择 Add deploy key.</span><br><span class="line"></span><br><span class="line">&lt;?php</span><br><span class="line">$raw_data = file_get_contents(<span class="string">"php://input"</span>);</span><br><span class="line">$pay_load = json_decode($raw_data,<span class="literal">true</span>);</span><br><span class="line"><span class="comment">//监测请求来源合法性，</span></span><br><span class="line"><span class="keyword">if</span>($pay_load[<span class="string">'password'</span>] != <span class="string">'pass'</span>)&#123;</span><br><span class="line">    exit(<span class="string">'ok 400'</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//检查是否为master分支</span></span><br><span class="line"><span class="keyword">if</span>($pay_load[<span class="string">"ref"</span>] != <span class="string">"refs/heads/master"</span>)&#123;</span><br><span class="line">    exit(<span class="string">'ok 401'</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">exec(<span class="string">'sh /var/www/hooks/build.sh'</span>);</span><br><span class="line"></span><br><span class="line"><span class="meta">#! /bin/bash</span></span><br><span class="line">SITE_PATH=<span class="string">'/var/www/weixinbook'</span></span><br><span class="line">USER=<span class="string">'www-data'</span></span><br><span class="line">USERGROUP=<span class="string">'www-data'</span></span><br><span class="line">cd $SITE_PATH</span><br><span class="line">git reset --hard origin/master</span><br><span class="line">git clean -f</span><br><span class="line">git pull</span><br><span class="line">git checkout master</span><br><span class="line">chown -R $USER:$USERGROUP $SITE_PATH</span><br></pre></td></tr></table></figure>
<h3 id="删除某个文件的所有历史记录"><a href="#删除某个文件的所有历史记录" class="headerlink" title="删除某个文件的所有历史记录"></a>删除某个文件的所有历史记录</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ git filter-branch -f --tree-filter <span class="string">'rm -rf common/service/SyncBlogServince.php'</span> HEAD</span><br><span class="line">$ git push origin --force</span><br><span class="line">http:<span class="comment">//www.54php.cn/default/90.html</span></span><br></pre></td></tr></table></figure>
<h3 id="批量kill进程"><a href="#批量kill进程" class="headerlink" title="批量kill进程"></a>批量kill进程</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -ef|grep <span class="string">'python'</span> |grep -v grep| awk <span class="string">'&#123;print $2&#125;’ | xargs kill -9</span></span><br></pre></td></tr></table></figure>
<h3 id="nginx日志按日期切割并保留最近七天的日志"><a href="#nginx日志按日期切割并保留最近七天的日志" class="headerlink" title="nginx日志按日期切割并保留最近七天的日志"></a>nginx日志按日期切割并保留最近七天的日志</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line">## 零点执行该脚本https://www.einsition.com/article/5/details</span><br><span class="line"></span><br><span class="line">## Nginx 日志文件所在的目录</span><br><span class="line">LOGS_PATH=<span class="string">"/www/log/nginx"</span></span><br><span class="line"></span><br><span class="line">mkdir -p $&#123;LOGS_PATH&#125;/backup/</span><br><span class="line"></span><br><span class="line">mv $&#123;LOGS_PATH&#125;/api.einsition.com-access.log $&#123;LOGS_PATH&#125;/backup/api.einsition.com-access_$(date -d <span class="string">"yesterday"</span> +<span class="string">"%Y%m%d"</span>).log</span><br><span class="line">mv $&#123;LOGS_PATH&#125;/api.einsition.com-error.log $&#123;LOGS_PATH&#125;/backup/api.einsition.com-error_$(date -d <span class="string">"yesterday"</span> +<span class="string">"%Y%m%d"</span>).log</span><br><span class="line"></span><br><span class="line">## 向 Nginx 主进程发送 USR1 信号。USR1 信号是重新打开日志文件</span><br><span class="line"># nginx_pid=`ps -ef |grep -v grep |grep "nginx: master process"|awk -F" " '&#123;print $2&#125;'`</span><br><span class="line"># kill -USR1 $nginx_pid</span><br><span class="line">kill -USR1 $(cat /run/nginx.pid)</span><br><span class="line"></span><br><span class="line">cd $&#123;LOGS_PATH&#125;/backup/</span><br><span class="line">find . -name <span class="string">"*.einsition.com*.log"</span> -type f -mtime +<span class="number">7</span> -exec rm -f &#123;&#125; \;</span><br></pre></td></tr></table></figure>
<h3 id="检测端口是否打开"><a href="#检测端口是否打开" class="headerlink" title="检测端口是否打开"></a>检测端口是否打开</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">yum install -y nc</span><br><span class="line">[root@su html]# nc -v www.buyao.bid 5050</span><br><span class="line">Ncat: Version <span class="number">7.50</span> ( https:<span class="comment">//nmap.org/ncat )</span></span><br><span class="line">Ncat: Connected to <span class="number">38.143</span><span class="number">.1</span><span class="number">.156</span>:<span class="number">5050.</span></span><br><span class="line">[root@su html]# nc -v  baidu.com 8123</span><br><span class="line">Ncat: Version <span class="number">7.50</span> ( https:<span class="comment">//nmap.org/ncat )</span></span><br><span class="line">Ncat: Connection to <span class="number">123.125</span><span class="number">.115</span><span class="number">.110</span> failed: Connection timed out.</span><br><span class="line">Ncat: Trying next address...</span><br><span class="line">♥</span><br><span class="line">[root@su html]# nc -v  baidu.com 443</span><br><span class="line">Ncat: Version <span class="number">7.50</span> ( https:<span class="comment">//nmap.org/ncat )</span></span><br><span class="line">Ncat: Connected to <span class="number">123.125</span><span class="number">.115</span><span class="number">.110</span>:<span class="number">443.</span></span><br></pre></td></tr></table></figure>
<h3 id="Composer-设置忽略版本匹配"><a href="#Composer-设置忽略版本匹配" class="headerlink" title="Composer 设置忽略版本匹配"></a>Composer 设置忽略版本匹配</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">vagrant@homestead:<span class="regexp">/usr/</span>share/nginx/html/laravel-blog$ sudo composer install</span><br><span class="line">Loading composer repositories <span class="keyword">with</span> package information</span><br><span class="line">Installing dependencies (including <span class="built_in">require</span>-dev) <span class="keyword">from</span> lock file</span><br><span class="line">Your requirements could not be resolved to an installable set <span class="keyword">of</span> packages.</span><br><span class="line">Problem <span class="number">1</span></span><br><span class="line">- Installation request <span class="keyword">for</span> doctrine/instantiator <span class="number">1.0</span><span class="number">.3</span> -&gt; satisfiable by doctrine/instantiator[<span class="number">1.0</span><span class="number">.3</span>].</span><br><span class="line">- doctrine/instantiator <span class="number">1.0</span><span class="number">.3</span> requires php ~<span class="number">5.3</span> -&gt; your PHP version (<span class="number">7.0</span><span class="number">.3</span>) does not satisfy that requirement.</span><br><span class="line">Problem <span class="number">2</span></span><br><span class="line">- doctrine/instantiator <span class="number">1.0</span><span class="number">.3</span> requires php ~<span class="number">5.3</span> -&gt; your PHP version (<span class="number">7.0</span><span class="number">.3</span>) does not satisfy that requirement.</span><br><span class="line">- phpunit/phpunit-mock-objects <span class="number">2.3</span><span class="number">.0</span> requires doctrine/instantiator ~<span class="number">1.0</span>,&gt;=<span class="number">1.0</span><span class="number">.1</span> -&gt; satisfiable by doctrine/instantiator[<span class="number">1.0</span><span class="number">.3</span>].</span><br><span class="line">- Installation request <span class="keyword">for</span> phpunit/phpunit-mock-objects <span class="number">2.3</span><span class="number">.0</span> -&gt; satisfiable by phpunit/phpunit-mock-objects[<span class="number">2.3</span><span class="number">.0</span>].</span><br><span class="line">提示我的PHP <span class="number">7</span>版本太高，不符合composer.json需要的版本，但是在PHP <span class="number">7</span>下应该也是可以运行的，composer可以设置忽略版本匹配，命令是：</span><br><span class="line"></span><br><span class="line">解决方案https:<span class="comment">//blog.fastrun.cn/2016/05/05/1-24/</span></span><br><span class="line">composer install --ignore-platform-reqs</span><br><span class="line">or</span><br><span class="line"></span><br><span class="line">composer update --ignore-platform-reqs</span><br></pre></td></tr></table></figure>
<h3 id="linux-1"><a href="#linux-1" class="headerlink" title="linux"></a>linux</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">统计 IP 连接数</span><br><span class="line">$ netstat -ntu | awk <span class="string">'&#123;print $5&#125;'</span> | cut -d: -f1 | sort | uniq -c | sort -rn | head <span class="number">-10</span></span><br><span class="line"></span><br><span class="line"># 当前用户</span><br><span class="line">$ whoami</span><br><span class="line">root</span><br><span class="line"># 当前所有用户</span><br><span class="line">$ ps -ef | grep <span class="string">'pts'</span></span><br><span class="line">root      <span class="number">4752</span>  <span class="number">4727</span>  <span class="number">0</span> <span class="number">00</span>:<span class="number">09</span> pts/<span class="number">0</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> su www</span><br><span class="line">www       <span class="number">4755</span>  <span class="number">4752</span>  <span class="number">0</span> <span class="number">00</span>:<span class="number">09</span> pts/<span class="number">0</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> bash</span><br><span class="line">剔除非法登陆用户：https:<span class="comment">//www.fanhaobai.com/2018/01/linux-skill.html</span></span><br><span class="line"></span><br><span class="line">$ kill <span class="number">-9</span> <span class="number">4755</span></span><br></pre></td></tr></table></figure>
<h3 id="深入-Nginx-之配置篇"><a href="#深入-Nginx-之配置篇" class="headerlink" title="深入 Nginx 之配置篇"></a>深入 Nginx 之配置篇</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line">user admin; #配置用户或者组。</span><br><span class="line"></span><br><span class="line">worker_processes 4; #允许生成的进程数，默认为1 </span><br><span class="line"></span><br><span class="line">pid /nginx/pid/nginx.pid; #指定 nginx 进程运行文件存放地址 </span><br><span class="line"></span><br><span class="line">error_log log/error.log debug; #错误日志路径，级别。</span><br><span class="line">http &#123;</span><br><span class="line">    include       mime.types;   #文件扩展名与文件类型映射表</span><br><span class="line"></span><br><span class="line">    default_type  application/octet-stream; #默认文件类型，默认为text/plain</span><br><span class="line"></span><br><span class="line">    access_log off; #取消服务日志    </span><br><span class="line"></span><br><span class="line">    sendfile on;   #允许 sendfile 方式传输文件，默认为off，可以在http块，server块，location块。</span><br><span class="line"></span><br><span class="line">    sendfile_max_chunk 100k;  #每个进程每次调用传输数量不能大于设定的值，默认为0，即不设上限。</span><br><span class="line"></span><br><span class="line">    keepalive_timeout 65;  #连接超时时间，默认为75s，可以在http，server，location块。</span><br><span class="line"></span><br><span class="line">    server </span><br><span class="line">    &#123;</span><br><span class="line">            keepalive_requests 120; #单连接请求上限次数。</span><br><span class="line"></span><br><span class="line">            listen 80; #监听端口</span><br><span class="line"></span><br><span class="line">            server_name  127.0.0.1;   #监听地址      </span><br><span class="line"></span><br><span class="line">            index index.html index.htm index.php;</span><br><span class="line"></span><br><span class="line">            root your_path;  #根目录</span><br><span class="line"></span><br><span class="line">            location ~ \.php$</span><br><span class="line">            &#123;</span><br><span class="line">                  fastcgi_pass unix:<span class="regexp">/var/</span>run/php/php7<span class="number">.1</span>-fpm.sock;</span><br><span class="line"></span><br><span class="line">                  #fastcgi_pass 127.0.0.1:9000;</span><br><span class="line"></span><br><span class="line">                  fastcgi_index index.php;</span><br><span class="line"></span><br><span class="line">                  include fastcgi_params;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;upstream test-upstream &#123;</span><br><span class="line">     ip_hash; # 使用 ip_hash 算法分配 https://learnku.com/articles/24795#topnav</span><br><span class="line"> </span><br><span class="line">     server 192.168.1.1; # 要分配的 ip</span><br><span class="line">     server <span class="number">192.168</span><span class="number">.1</span><span class="number">.2</span>;</span><br><span class="line"> &#125;</span><br><span class="line"> </span><br><span class="line"> server &#123;</span><br><span class="line"> </span><br><span class="line">     location / &#123;       </span><br><span class="line">         proxy_pass http:<span class="comment">//test-upstream;</span></span><br><span class="line">     &#125;</span><br><span class="line"> </span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
<h3 id="nginx日志中提取5分钟内访问状态非200的记录"><a href="#nginx日志中提取5分钟内访问状态非200的记录" class="headerlink" title="nginx日志中提取5分钟内访问状态非200的记录"></a>nginx日志中提取5分钟内访问状态非200的记录</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">nginx部分访问日志如下：</span><br><span class="line"></span><br><span class="line"><span class="number">100.0</span><span class="number">.0</span><span class="number">.16</span> - - [<span class="number">27</span>/Aug/<span class="number">2015</span>:<span class="number">10</span>:<span class="number">44</span>:<span class="number">58</span> +<span class="number">0000</span>] GET www HTTP/<span class="number">1.1</span> “<span class="number">200</span>” <span class="number">15</span> “-” “-” “-” “<span class="number">3.254</span>” “<span class="number">192.168</span><span class="number">.1</span><span class="number">.1</span>:<span class="number">80</span>”</span><br><span class="line"></span><br><span class="line"><span class="number">100.0</span><span class="number">.1</span><span class="number">.13</span> - - [<span class="number">27</span>/Aug/<span class="number">2015</span>:<span class="number">10</span>:<span class="number">45</span>:<span class="number">22</span> +<span class="number">0000</span>] GET www HTTP/<span class="number">1.1</span> “<span class="number">200</span>” <span class="number">90</span> “-” “-” “-” “<span class="number">0.498</span>” “<span class="number">192.168</span><span class="number">.1</span><span class="number">.1</span>:<span class="number">80</span>”</span><br><span class="line"></span><br><span class="line"><span class="number">100.0</span><span class="number">.1</span><span class="number">.13</span> - - [<span class="number">27</span>/Aug/<span class="number">2015</span>:<span class="number">10</span>:<span class="number">46</span>:<span class="number">26</span> +<span class="number">0000</span>] GET www HTTP/<span class="number">1.1</span> “<span class="number">200</span>” <span class="number">90</span> “-” “-” “-” “<span class="number">1.704</span>” “<span class="number">192.168</span><span class="number">.1</span><span class="number">.1</span>:<span class="number">80</span>”</span><br><span class="line"></span><br><span class="line"><span class="number">100.0</span><span class="number">.1</span><span class="number">.16</span> - - [<span class="number">27</span>/Aug/<span class="number">2015</span>:<span class="number">10</span>:<span class="number">46</span>:<span class="number">35</span> +<span class="number">0000</span>] GET www HTTP/<span class="number">1.1</span> “<span class="number">200</span>” <span class="number">94</span> “-” “-” “-” “<span class="number">1.189</span>” “<span class="number">192.168</span><span class="number">.1</span><span class="number">.1</span>:<span class="number">80</span>”</span><br><span class="line"></span><br><span class="line">采用awk多分隔符实现</span><br><span class="line">awk -F<span class="string">'[/ "]'</span> <span class="string">'$6&gt;="2015:10:44:00" &amp;&amp; $6&lt;="2015:10:49:00" &amp;&amp; $13 != 200'</span></span><br><span class="line"></span><br><span class="line">分析<span class="number">2015</span>/<span class="number">8</span>/<span class="number">15</span> 到 <span class="number">2015</span>/<span class="number">8</span>/<span class="number">16</span> 访问<span class="string">"/index.php?g=Member&amp;m=Public&amp;a=sendValidCode"</span>的IP倒序排列</span><br><span class="line"></span><br><span class="line">cat log_file | egrep <span class="string">'15/Aug/2015|16/Aug/2015'</span> | awk <span class="string">'&#123;if($7 == "/index.php?g=Member&amp;m=Public&amp;a=sendValidCode") print $1,$7&#125;'</span>|sort|uniq -c|sort -nr</span><br></pre></td></tr></table></figure>
<h3 id="golang入门"><a href="#golang入门" class="headerlink" title="golang入门"></a>golang入门</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> b []int</span><br><span class="line">numbers := make([]int,<span class="number">5</span>,<span class="number">10</span>)</span><br><span class="line"><span class="comment">// 创建切片</span></span><br><span class="line">number2 := make([]int, <span class="number">15</span>)</span><br><span class="line"><span class="comment">// 将原始切片复制到新切片</span></span><br><span class="line">copy(number2, number)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 初始化长度为 4，以及赋值</span></span><br><span class="line">number2 := []int&#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>&#125;</span><br><span class="line">fmt.Println(numbers) <span class="comment">// -&gt; [1 2 3 4]</span></span><br><span class="line"><span class="comment">// 创建子切片</span></span><br><span class="line">slice1 := number2[<span class="number">2</span>:]</span><br><span class="line">fmt.Println(slice1) <span class="comment">// -&gt; [3 4]</span></span><br><span class="line">slice2 := number2[:<span class="number">3</span>]</span><br><span class="line">fmt.Println(slice2) <span class="comment">// -&gt; [1 2 3]</span></span><br><span class="line">slice3 := number2[<span class="number">1</span>:<span class="number">4</span>]</span><br><span class="line">fmt.Println(slice3) <span class="comment">// -&gt; [2 3 4]</span></span><br><span class="line"><span class="keyword">if</span> num := <span class="number">9</span>; num &lt; <span class="number">0</span> &#123;</span><br><span class="line"> fmt.Println(num, <span class="string">"is negative"</span>)</span><br><span class="line">&#125; <span class="keyword">else</span> <span class="keyword">if</span> num &lt; <span class="number">10</span> &#123;</span><br><span class="line"> fmt.Println(num, <span class="string">"has 1 digit"</span>)</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line"> fmt.Println(num, <span class="string">"has multiple digits"</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> ap *int ap  是指向整数类型的指针。＆ 运算符可用于获取变量的地址。</span><br><span class="line">            </span><br><span class="line">            a := <span class="number">12</span></span><br><span class="line">            ap = &amp;a</span><br><span class="line">            可以使用 * 运算符访问指针指向的值：</span><br><span class="line">            </span><br><span class="line">            fmt.Println(*ap)</span><br><span class="line">            <span class="comment">// =&gt; 12</span></span><br><span class="line"> func increment(i *int) &#123;</span><br><span class="line">   *i++</span><br><span class="line"> &#125;</span><br><span class="line"> func main() &#123;</span><br><span class="line">   i := <span class="number">10</span></span><br><span class="line">   increment(&amp;i)</span><br><span class="line">   fmt.Println(i)</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="comment">//=&gt; 11</span></span><br><span class="line"> func add(a int, b int) int &#123;</span><br><span class="line">   c := a + b</span><br><span class="line">   <span class="keyword">return</span> c</span><br><span class="line"> &#125;           </span><br><span class="line">   func add(a int, b int) (c int) &#123;</span><br><span class="line">     c = a + b</span><br><span class="line">     <span class="keyword">return</span></span><br><span class="line">   &#125;         </span><br><span class="line">    func add(a int, b int) (int, string) &#123;</span><br><span class="line">      c := a + b</span><br><span class="line">      <span class="keyword">return</span> c, <span class="string">"successfully added"</span></span><br><span class="line">    &#125; </span><br><span class="line">    type person struct &#123;</span><br><span class="line">      name string</span><br><span class="line">      age int</span><br><span class="line">      gender string</span><br><span class="line">    &#125;</span><br><span class="line">   <span class="comment">//方式1：指定属性和值</span></span><br><span class="line">   p = person&#123;<span class="attr">name</span>: <span class="string">"Bob"</span>, <span class="attr">age</span>: <span class="number">42</span>, <span class="attr">gender</span>: <span class="string">"Male"</span>&#125;</span><br><span class="line">   <span class="comment">//方式2：指定值</span></span><br><span class="line">   person&#123;<span class="string">"Bob"</span>, <span class="number">42</span>, <span class="string">"Male"</span>&#125;</span><br><span class="line">   p.name</span><br><span class="line">   <span class="comment">//=&gt; Bob</span></span><br><span class="line">   </span><br><span class="line">   pp = &amp;person&#123;<span class="attr">name</span>: <span class="string">"Bob"</span>, <span class="attr">age</span>: <span class="number">42</span>, <span class="attr">gender</span>: <span class="string">"Male"</span>&#125;</span><br><span class="line">   pp.name</span><br><span class="line">   <span class="comment">//=&gt; Bob</span></span><br><span class="line">   </span><br><span class="line"><span class="comment">//定义结构体</span></span><br><span class="line">type person struct &#123;</span><br><span class="line">  name   string</span><br><span class="line">  age    int</span><br><span class="line">  gender string</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 方法定义</span></span><br><span class="line">func (p *person) describe() &#123;</span><br><span class="line">  fmt.Printf(<span class="string">"%v is %v years old."</span>, p.name, p.age)</span><br><span class="line">&#125;</span><br><span class="line">func (p *person) setAge(age int) &#123;</span><br><span class="line">  p.age = age</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">func (p person) setName(name string) &#123;</span><br><span class="line">  p.name = name</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">func main() &#123;</span><br><span class="line">  pp := &amp;person&#123;<span class="attr">name</span>: <span class="string">"Bob"</span>, <span class="attr">age</span>: <span class="number">42</span>, <span class="attr">gender</span>: <span class="string">"Male"</span>&#125;</span><br><span class="line">  pp.describe()</span><br><span class="line">  <span class="comment">// =&gt; Bob is 42 years old</span></span><br><span class="line">  pp.setAge(<span class="number">45</span>)</span><br><span class="line">  fmt.Println(pp.age)</span><br><span class="line">  <span class="comment">//=&gt; 45</span></span><br><span class="line">  pp.setName(<span class="string">"Hari"</span>)</span><br><span class="line">  fmt.Println(pp.name)</span><br><span class="line">  <span class="comment">//=&gt; Bob</span></span><br><span class="line">&#125;</span><br><span class="line">Go 的接口是一系列方法的集合。接口有助于将类型的属性组合在一起 结构体是不同字段的类型集合。 结构用于将数据分组在一起。</span><br><span class="line">type animal interface &#123;</span><br><span class="line">  description() string</span><br><span class="line">&#125;</span><br><span class="line">type cat struct &#123;</span><br><span class="line">  Type  string</span><br><span class="line">  Sound string</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">type snake struct &#123;</span><br><span class="line">  Type      string</span><br><span class="line">  Poisonous bool</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">func (s snake) description() string &#123;</span><br><span class="line">  <span class="keyword">return</span> fmt.Sprintf(<span class="string">"Poisonous: %v"</span>, s.Poisonous)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">func (c cat) description() string &#123;</span><br><span class="line">  <span class="keyword">return</span> fmt.Sprintf(<span class="string">"Sound: %v"</span>, c.Sound)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">func main() &#123;</span><br><span class="line">  <span class="keyword">var</span> a animal</span><br><span class="line">  a = snake&#123;<span class="attr">Poisonous</span>: <span class="literal">true</span>&#125;</span><br><span class="line">  fmt.Println(a.description())</span><br><span class="line">  a = cat&#123;<span class="attr">Sound</span>: <span class="string">"Meow!!!"</span>&#125;</span><br><span class="line">  fmt.Println(a.description())</span><br><span class="line">&#125;</span><br><span class="line">godoc person Description</span><br><span class="line"> 它将会为我们的 person 包内部的 Description 函数生成文档。查看文档的话只需要使用如下命令启动一个 web 服务器就可以：</span><br><span class="line"> </span><br><span class="line"> godoc -http=<span class="string">":8080"</span></span><br><span class="line"> 现在去访问这个 URL http:<span class="comment">//localhost:8080/pkg/ 然后你就可以看到我们刚创建的包文档了。</span></span><br><span class="line">func main()&#123;</span><br><span class="line">  resp, <span class="attr">err</span> := http.Get(<span class="string">"http://example.com/"</span>)</span><br><span class="line">  <span class="keyword">if</span> err != nil &#123;</span><br><span class="line">    fmt.Println(err)</span><br><span class="line">    <span class="keyword">return</span></span><br><span class="line">  &#125;</span><br><span class="line">  fmt.Println(resp)</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/golang/t/24715#reply83037</span></span><br></pre></td></tr></table></figure>
<h3 id="linux-chmod"><a href="#linux-chmod" class="headerlink" title="linux chmod"></a>linux chmod</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="number">777</span> --- 代表所有人都有最高权限</span><br><span class="line"><span class="number">755</span> --- 执行文件的常用权限</span><br><span class="line"><span class="number">644</span> --- 普通文件的常用权限</span><br><span class="line">关于为什么有文件的写权限，却不能删除文件的问题解释</span><br><span class="line"></span><br><span class="line">对于某个目录或文件拥有的w权限，针对的是里面的内容，而不是文件本身</span><br><span class="line"></span><br><span class="line">由此，对文件的删除是对文件所在目录的写，故必须有目录的写权限才可以</span><br><span class="line">对文件来讲： 最高权限是 x（执行）</span><br><span class="line">对目录来讲： 最高权限是 w（写）具有修改目录结构的权限。如新建文件和目录，删除此目录下文件和目录，重命名此目录下文件和目录，剪切</span><br><span class="line"></span><br><span class="line">针对目录</span><br><span class="line"><span class="number">755</span>是最常用的权限设定方式，（目录所有者可以删除和创建目录下文件，其他人只能进入看看）</span><br><span class="line"></span><br><span class="line">稍微严谨一点是<span class="number">750</span>，其他人进都进不来</span><br><span class="line"></span><br><span class="line">极端严谨一点是<span class="number">700</span>，就我自己能进能看能改，其他所有拒之门外</span><br><span class="line">针对普通文件</span><br><span class="line"><span class="number">644</span>是最常用的权限设定方式，（文件所有者能看能改，其他人只能看）</span><br><span class="line"></span><br><span class="line"><span class="number">640</span>是其他人不能看不能改</span><br><span class="line"></span><br><span class="line"><span class="number">600</span>是其他所有人不能看不能改</span><br><span class="line">针对可执行文件</span><br><span class="line"><span class="number">754</span>是最常用的权限设定方式，（文件所有者可以看改执行，组内可以执行，其他人只能看）</span><br><span class="line"></span><br><span class="line"><span class="number">750</span>、<span class="number">740</span>、<span class="number">700</span>都是可以的</span><br><span class="line">还有一点</span><br><span class="line">文件所有者必须为<span class="number">7</span>或者是<span class="number">6</span>，要不就是傻逼 https:<span class="comment">//learnku.com/articles/22095#topnav</span></span><br><span class="line"></span><br><span class="line">通过 kill ps -ef | grep <span class="string">'ddd'</span> https:<span class="comment">//learnku.com/articles/21339#topnav</span></span><br><span class="line"></span><br><span class="line">这种形式，这个时候实际上等同于拼接字符串得到的命令，其效果类似于 kill $pid</span><br><span class="line"><span class="keyword">for</span> procid <span class="keyword">in</span> $(ps -aux | grep <span class="string">"some search"</span> | awk <span class="string">'&#123;print $2&#125;'</span>); <span class="keyword">do</span> kill <span class="number">-9</span> $procid; done</span><br><span class="line"></span><br><span class="line">其实与第一种原理一样，只不过需要多次kill的时候是循环处理的，每次处理一个</span><br><span class="line">ps -ef | grep <span class="string">'ddd'</span> | xargs kill</span><br><span class="line">echo <span class="string">'11@22@33@44@55@66@77@88@99@00'</span> | xargs -d <span class="string">'@'</span> -n <span class="number">3</span> echo</span><br><span class="line">输出结果：</span><br><span class="line"></span><br><span class="line"><span class="number">11</span> <span class="number">22</span> <span class="number">33</span></span><br><span class="line"><span class="number">44</span> <span class="number">55</span> <span class="number">66</span></span><br><span class="line"><span class="number">77</span> <span class="number">88</span> <span class="number">99</span></span><br><span class="line"><span class="number">00</span></span><br><span class="line">find的输出结果是每条记录后面加上换行，也就是每条记录是一个新行</span><br><span class="line">find . -name <span class="string">"*.txt"</span> -print0</span><br><span class="line">输出：</span><br><span class="line"></span><br><span class="line">./<span class="number">2.</span>txt./<span class="number">3.</span>txt./<span class="number">1.</span>txt     =&gt; 加上 -print0 参数表示find输出的每条结果后面加上 <span class="string">'\0'</span> 而不是换行</span><br><span class="line">find . -name <span class="string">"*.txt"</span> -print0 | xargs <span class="number">-0</span> echo</span><br><span class="line">输出：</span><br><span class="line"></span><br><span class="line">./<span class="number">2.</span>txt ./<span class="number">3.</span>txt ./<span class="number">1.</span>txt</span><br></pre></td></tr></table></figure>
<h3 id="nginx-配置"><a href="#nginx-配置" class="headerlink" title="nginx 配置"></a>nginx 配置</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">禁止空主机头和未授权域名访问</span><br><span class="line">$ vim conf.d/<span class="keyword">default</span>.conf</span><br><span class="line">server &#123;</span><br><span class="line">     listen <span class="number">80</span> <span class="keyword">default</span>;</span><br><span class="line">     server_name _;</span><br><span class="line">     <span class="keyword">return</span> <span class="number">500</span>;</span><br><span class="line">&#125;</span><br><span class="line">$ vim vhosts/blog.yiranzai.cn.conf</span><br><span class="line">server &#123;</span><br><span class="line">    listen       <span class="number">80</span>;</span><br><span class="line">    server_name  blog.yiranzai.cn;</span><br><span class="line">    location / &#123;</span><br><span class="line">        proxy_pass http:<span class="comment">//127.0.0.1:88;</span></span><br><span class="line">	    include /etc/nginx/proxy.conf;       #代理配置</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">$ vim proxy.conf</span><br><span class="line">proxy_set_header   Host             $host;</span><br><span class="line">proxy_set_header   X-Real-IP        $remote_addr;</span><br><span class="line">proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;</span><br><span class="line">$ firewall-cmd --zone=public --add-port=<span class="number">80</span>/tcp --permanent</span><br><span class="line">success</span><br><span class="line">$ firewall-cmd --reload</span><br><span class="line">success</span><br><span class="line">systemctl start nginx.service           #启动nginx</span><br><span class="line">systemctl enable nginx.service          #将nginx开机启动</span><br><span class="line">systemctl stop nginx.service            #停止nginx服务</span><br><span class="line">systemctl reload nginx.service          #重新加载nginx配置（推荐）</span><br><span class="line">systemctl restart nginx.service         #重启nginx服务（不推荐，会关闭所有进程）</span><br><span class="line"></span><br><span class="line">php-fpm  </span><br><span class="line">fastcgi_finish_request() - 特殊功能：用于在请求完成和刷新数据后，继续在后台执行耗时的工作（录入视频转换、统计处理等）；</span><br></pre></td></tr></table></figure>
<h3 id="svn搭建"><a href="#svn搭建" class="headerlink" title="svn搭建"></a>svn搭建</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">yum install -y subversion</span><br><span class="line"></span><br><span class="line">$ mkdir /<span class="keyword">var</span>/www/svn</span><br><span class="line">$ cd /<span class="keyword">var</span>/www/svn</span><br><span class="line">$ svnadmin create /<span class="keyword">var</span>/www/svn</span><br><span class="line">$ ls</span><br><span class="line">conf  db  format  hooks  locks  README.txt</span><br><span class="line">$ vim conf/passwd</span><br><span class="line">[users]</span><br><span class="line"># harry = harryssecret</span><br><span class="line"># 账号 = 密码</span><br><span class="line">svn = svnpasswd</span><br><span class="line">svnre = svnrepasswd</span><br><span class="line">$ vim conf/authz</span><br><span class="line">[<span class="regexp">/]         /</span><span class="regexp">/仓库下所有文件</span></span><br><span class="line"><span class="regexp">svn=rw      /</span><span class="regexp">/可读可写</span></span><br><span class="line"><span class="regexp">svnre=r     /</span><span class="regexp">/只读</span></span><br><span class="line"><span class="regexp">*=          /</span><span class="regexp">/其他用户无任何权限$ vim conf/</span>svnserve.conf</span><br><span class="line">                       </span><br><span class="line">                       anon-access = read #匿名用户可读</span><br><span class="line">                       auth-access = write #授权用户可写</span><br><span class="line">                       password-db = passwd #使用哪个文件作为账号文件</span><br><span class="line">                       authz-db = authz #使用哪个文件作为权限文件</span><br><span class="line">                       realm = /var/www/svn/ # 认证空间名，版本库所在目录</span><br><span class="line">$ svnserve -d -r /<span class="keyword">var</span>/www/svn                       <span class="comment">//-d 表示守护进程， -r 表示在后台执行，默认端口为3690</span></span><br><span class="line">$ svnserve -d -r --listen-port <span class="number">3691</span> /<span class="keyword">var</span>/www/svn    <span class="comment">//指定3691端口启动该服务</span></span><br><span class="line">$ killall svnserve                                  <span class="comment">//停止全部</span></span><br><span class="line">$ ps -ef | grep svnserve</span><br><span class="line">root      <span class="number">4148</span>     <span class="number">1</span>  <span class="number">0</span> Dec12 ?        <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> svnserve -d -r /<span class="keyword">var</span>/www/svn/a/</span><br><span class="line">root      <span class="number">8995</span>     <span class="number">1</span>  <span class="number">0</span> Dec09 ?        <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> svnserve -d -r /<span class="keyword">var</span>/www/svn/b/ --listen-port <span class="number">3691</span></span><br><span class="line">root     <span class="number">14855</span>     <span class="number">1</span>  <span class="number">0</span> Dec19 ?        <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> svnserve -d -r /<span class="keyword">var</span>/www/svn/c/ --listen-port <span class="number">3692</span></span><br><span class="line">root     <span class="number">27538</span> <span class="number">27343</span>  <span class="number">0</span> <span class="number">09</span>:<span class="number">39</span> pts/<span class="number">0</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">00</span> grep --color=auto svnserve</span><br><span class="line">$ kill <span class="number">8995</span>                 <span class="comment">//停止3692端口的svnserve                       </span></span><br><span class="line">windows中使用TortoiseSVN连接，输入地址 svn:<span class="comment">//118.24.158.116/ 即可，不出意外输入用户名svn和密码svnrepasswd就能连接成功了。</span></span><br><span class="line">默认端口<span class="number">3690</span>，如果你修改了端口，那么要记得加上端口号。</span><br></pre></td></tr></table></figure>
<h3 id="Git-钩子检查-PHP-语法和代码规范"><a href="#Git-钩子检查-PHP-语法和代码规范" class="headerlink" title="Git 钩子检查 PHP 语法和代码规范"></a>Git 钩子检查 PHP 语法和代码规范</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line">#</span><br><span class="line"># (c) Copyright codcodog</span><br><span class="line">#</span><br><span class="line"># PHP 语法检查以及代码规范检查 https://github.com/codcodog/phpconfig/blob/master/git/pre-commit</span><br><span class="line">#如果该钩子以非零值退出，Git 将放弃此次提交，不过你可以用 git commit --no-verify 来绕过这个环节</span><br><span class="line"># 依赖：</span><br><span class="line"># - php-cs-fixer</span><br><span class="line"># - php-parallel-lint</span><br><span class="line"></span><br><span class="line">set -e</span><br><span class="line"></span><br><span class="line">PHP=<span class="string">'php'</span></span><br><span class="line">CODE_STYLE_CHECK=<span class="string">'vendor/bin/php-cs-fixer fix --dry-run --diff --diff-format=udiff -vvv'</span></span><br><span class="line">CODE_SYNTAX_CHECK=<span class="string">'vendor/bin/parallel-lint -j 10'</span></span><br><span class="line"></span><br><span class="line">files=$(git diff --cached --name-only)</span><br><span class="line"></span><br><span class="line"># 若 host 没有安装 PHP</span><br><span class="line"># 则使用 docker 环境的 PHP</span><br><span class="line">is_docker_php()</span><br><span class="line">&#123;</span><br><span class="line">  <span class="keyword">if</span> ! command -v $PHP &gt; <span class="regexp">/dev/</span><span class="literal">null</span> <span class="number">2</span>&gt;&amp;<span class="number">1</span>; then</span><br><span class="line">    PHP=<span class="string">'docker exec php php'</span></span><br><span class="line">    CODE_STYLE_CHECK=<span class="string">"$PHP $CODE_STYLE_CHECK"</span></span><br><span class="line">    CODE_SYNTAX_CHECK=<span class="string">"$PHP $CODE_SYNTAX_CHECK"</span></span><br><span class="line">  fi</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">is_php()</span><br><span class="line">&#123;</span><br><span class="line">  file_extension=<span class="string">"$&#123;1##*.&#125;"</span></span><br><span class="line">  <span class="keyword">if</span> [[ <span class="string">"$file_extension"</span> == <span class="string">'php'</span> ]]; then</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span></span><br><span class="line">  fi</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> <span class="number">1</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">check_syntax()</span><br><span class="line">&#123;</span><br><span class="line">  <span class="keyword">if</span> ! $CODE_SYNTAX_CHECK <span class="string">"$1"</span> &gt; <span class="regexp">/dev/</span><span class="literal">null</span> <span class="number">2</span>&gt;&amp;<span class="number">1</span>; then</span><br><span class="line">    $CODE_SYNTAX_CHECK <span class="string">"$1"</span></span><br><span class="line">    exit <span class="number">1</span></span><br><span class="line">  fi</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">check_style()</span><br><span class="line">&#123;</span><br><span class="line">  <span class="keyword">if</span> ! $CODE_STYLE_CHECK <span class="string">"$1"</span> &gt; <span class="regexp">/dev/</span><span class="literal">null</span> <span class="number">2</span>&gt;&amp;<span class="number">1</span>; then</span><br><span class="line">    $CODE_STYLE_CHECK <span class="string">"$1"</span></span><br><span class="line">    exit <span class="number">1</span></span><br><span class="line">  fi</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">main()</span><br><span class="line">&#123;</span><br><span class="line">  is_docker_php</span><br><span class="line">  <span class="keyword">for</span> f <span class="keyword">in</span> $files; <span class="keyword">do</span></span><br><span class="line">    <span class="keyword">if</span> is_php <span class="string">"$f"</span>; then</span><br><span class="line">      check_syntax <span class="string">"$f"</span></span><br><span class="line">      check_style <span class="string">"$f"</span></span><br><span class="line">    fi</span><br><span class="line">  done</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">main</span><br><span class="line">exit <span class="number">0</span></span><br></pre></td></tr></table></figure>
<h3 id="带宽被打满"><a href="#带宽被打满" class="headerlink" title="带宽被打满"></a>带宽被打满</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">apt-get install iftop</span><br><span class="line">根据阿里云的监控面板是网卡<span class="number">1</span>（eth1）流量异常，所以通过 iftop 工具监控下 eth1 的流量：</span><br><span class="line">https:<span class="comment">//laravelacademy.org/post/9838.html</span></span><br><span class="line">iftop -i eth1 -P  <span class="comment">// 带 -P 显示对应端口号</span></span><br><span class="line">iptables -I INPUT -s <span class="number">114.84</span><span class="number">.146</span><span class="number">.45</span> -j DROP</span><br></pre></td></tr></table></figure>
<h3 id="你可能会忽略的-Git-提交规范"><a href="#你可能会忽略的-Git-提交规范" class="headerlink" title="你可能会忽略的 Git 提交规范"></a>你可能会忽略的 Git 提交规范</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">&lt;type&gt;(&lt;scope&gt;): &lt;subject&gt;</span><br><span class="line">type</span><br><span class="line">用于说明 commit 的类别，只允许使用下面7个标识。https://learnku.com/articles/25456#topnav</span><br><span class="line"></span><br><span class="line">feat：新功能（feature）</span><br><span class="line">fix：修补bug</span><br><span class="line">docs：文档（documentation）</span><br><span class="line">style： 格式（不影响代码运行的变动）</span><br><span class="line">refactor：重构（即不是新增功能，也不是修改bug的代码变动）</span><br><span class="line">test：增加测试</span><br><span class="line">chore：构建过程或辅助工具的变动</span><br><span class="line">scope</span><br><span class="line"></span><br><span class="line">用于说明 commit 影响的范围，比如数据层、控制层、视图层等等，视项目不同而不同。</span><br><span class="line">subject</span><br><span class="line"></span><br><span class="line">是 commit 目的的简短描述，不超过50个字符。</span><br><span class="line">以动词开头，使用第一人称现在时，比如change，而不是changed或changes</span><br><span class="line">第一个字母小写</span><br><span class="line">结尾不加句号(.)</span><br><span class="line">Commit 规范的作用</span><br><span class="line"></span><br><span class="line">1、提供更多的信息，方便排查与回退;</span><br><span class="line">2、过滤关键字，迅速定位;</span><br><span class="line">3、方便生成文档;</span><br><span class="line">npm install -g conventional-changelog </span><br><span class="line">cd jartto-domo </span><br><span class="line">conventional-changelog -p angular -i CHANGELOG.md -w</span><br><span class="line">为了方便使用，可以将其写入 package.json 的 scripts 字段。</span><br><span class="line"></span><br><span class="line">&#123; </span><br><span class="line">  "scripts": &#123; </span><br><span class="line">    "changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0" </span><br><span class="line">  &#125; </span><br><span class="line">&#125;</span><br><span class="line">这样，使用起来就很简单了：https://www.conventionalcommits.org/zh/v1.0.0-beta.3/ </span><br><span class="line"></span><br><span class="line"> npm run changelog</span><br><span class="line">npm install --save-dev validate-commit-msg</span><br></pre></td></tr></table></figure>
<h3 id="git-pull或git-checkout-后保持权限不变"><a href="#git-pull或git-checkout-后保持权限不变" class="headerlink" title="git pull或git checkout 后保持权限不变"></a>git pull或git checkout 后保持权限不变</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//www.guaosi.com/2018/12/06/git-auto-change/</span></span><br><span class="line">服务器上的项目,一般都是使用用户组www-data或者www来保证权限安全,不会使用root的。但是git pull下来的新文件或者修改的文件,则会把原有的文件的权限更改为<span class="number">644</span>,用户组改为root</span><br><span class="line"></span><br><span class="line">chmod -R <span class="number">755</span> www.guaosi.com/</span><br><span class="line"># 修改项目内所有文件为755权限</span><br><span class="line">chown -R www-data:www-data www.guaosi.com/</span><br><span class="line"># 修改项目内所有文件的用户和用户组为www-data</span><br><span class="line"></span><br><span class="line">cd .git/hooks/</span><br><span class="line">vim post-merge</span><br><span class="line"><span class="meta">#!/bin/sh</span></span><br><span class="line">pwd</span><br><span class="line">echo <span class="string">"This is post-merge hook"</span></span><br><span class="line">chmod -R <span class="number">755</span> .<span class="comment">/* &amp;&amp; chown -R www-data:www-data ./*</span></span><br><span class="line"><span class="comment">chmod +x post-merge</span></span><br><span class="line"><span class="comment">vim post-checkout</span></span><br><span class="line"><span class="comment">#!/bin/sh</span></span><br><span class="line"><span class="comment">pwd</span></span><br><span class="line"><span class="comment">echo "This is post-checkout hook"</span></span><br><span class="line"><span class="comment">chmod -R 755 ./* &amp;&amp; chown -R www-data:www-data ./*</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">chmod +x post-checkout</span></span><br></pre></td></tr></table></figure>
<h3 id="Git-仓库迁移至其他服务器并实现-hooks-自动化部署"><a href="#Git-仓库迁移至其他服务器并实现-hooks-自动化部署" class="headerlink" title="Git 仓库迁移至其他服务器并实现 hooks 自动化部署"></a>Git 仓库迁移至其他服务器并实现 hooks 自动化部署</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//https://learnku.com/articles/26130</span></span><br><span class="line">一：git仓库迁移</span><br><span class="line"></span><br><span class="line"><span class="number">1.</span>把需要迁移的项目克隆一份至本地电脑上。</span><br><span class="line"></span><br><span class="line"><span class="comment">//从原地址克隆一份裸版本库，比如原本托管在旧服务器的私有仓库</span></span><br><span class="line"><span class="comment">//–bare 创建的克隆版本库都不包含工作区，直接就是版本库的内容，这样的版本库称为裸版本库。</span></span><br><span class="line">git clone --bare ssh:<span class="comment">//git@192.10.0.1/home/git/test.git</span></span><br><span class="line"><span class="number">2.</span>到新的 Git 服务器上创建一个新项目。</span><br><span class="line"></span><br><span class="line"><span class="comment">//切换git用户,没有需要创建git用户</span></span><br><span class="line">su - git</span><br><span class="line"><span class="comment">//进入git家目录</span></span><br><span class="line">cd /home/git</span><br><span class="line"><span class="comment">//创建项目</span></span><br><span class="line">mkdir test.git</span><br><span class="line"><span class="comment">//初始化一个裸仓库</span></span><br><span class="line">git init --bare test.git</span><br><span class="line"><span class="number">3.</span>切换到本地电脑，以镜像推送的方式上传代码到新的服务器上。</span><br><span class="line"></span><br><span class="line"><span class="comment">//进入第一步复制下来的test.git 项目</span></span><br><span class="line">cd test.git</span><br><span class="line"><span class="comment">//以镜像推送的方式上传代码到新的服务器上。</span></span><br><span class="line"><span class="comment">//请确保已经添加了公钥到新的机器上</span></span><br><span class="line">git push --mirror ssh:<span class="comment">//git@192.10.0.2/home/git/test.git</span></span><br><span class="line"><span class="number">4.</span>删除本地电脑的test.git 项目。</span><br><span class="line"></span><br><span class="line"><span class="comment">//rm -rf test.git</span></span><br><span class="line"><span class="number">5.</span>从新的git仓库中clone项目到本地。</span><br><span class="line"></span><br><span class="line">git clone ssh:<span class="comment">//git@192.10.0.2/home/git/test.git</span></span><br><span class="line">至此，git项目完整的迁移到了新的服务器上。</span><br><span class="line">二 hooks自动部署到网站根目录</span><br><span class="line"></span><br><span class="line"><span class="number">1.</span>把项目clone至本地根目录</span><br><span class="line"></span><br><span class="line">cd /<span class="keyword">var</span>/www/html             <span class="comment">//进入网站上级目录</span></span><br><span class="line">git clone /home/git/test.git <span class="comment">//test克隆test.git仓库到test网站根目录</span></span><br><span class="line">chmod -R <span class="number">777</span> test            <span class="comment">//给网站根目录设置权限</span></span><br><span class="line">chown -R git:git test        <span class="comment">//将git用户权限设置到test根目录上</span></span><br><span class="line"><span class="number">2.</span>设置钩子</span><br><span class="line"></span><br><span class="line">cd /home/git/test.git/hooks/</span><br><span class="line">vim post-receive</span><br><span class="line"><span class="comment">//将以下内容写入到 post-receive中，并给post-receive设置可读写权限</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line">IS_BARE=$(git rev-parse --is-bare-repository)</span><br><span class="line"><span class="keyword">if</span> [ -z <span class="string">"$IS_BARE"</span> ]; then</span><br><span class="line">echo &gt;&amp;<span class="number">2</span> <span class="string">"fatal: post-receive: IS_NOT_BARE"</span></span><br><span class="line">exit <span class="number">1</span></span><br><span class="line">fi</span><br><span class="line">unset GIT_DIR</span><br><span class="line">DeployPath=<span class="string">"/var/www/html/test"</span>  <span class="comment">//你的网站根目录</span></span><br><span class="line">cd $DeployPath</span><br><span class="line">git fetch --all</span><br><span class="line">git reset --hard origin/master</span><br></pre></td></tr></table></figure>
<h3 id="更新与回滚"><a href="#更新与回滚" class="headerlink" title="更新与回滚"></a>更新与回滚</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">$ cd /<span class="keyword">var</span>/www/deployment</span><br><span class="line">$ git remote set-url origin <span class="string">'git@github.com:wi1dcard/hello-deployment.git'</span></span><br><span class="line">git fetch 命令获取远端状态（但不拉取到本地）：</span><br><span class="line"></span><br><span class="line">$ git fetch -t -v</span><br><span class="line">穿越到远端 master 分支的倒数第一次提交（即最新提交），通常用于更新至最新代码。</span><br><span class="line"></span><br><span class="line">$ git reset --hard origin/master</span><br><span class="line">穿越到远端 master 分支倒数第三次提交，通常用于回滚一部分错误提交。</span><br><span class="line"></span><br><span class="line">$ git reset --hard origin/master~<span class="number">2</span></span><br><span class="line">穿越到 ID 为 <span class="number">602</span>fa83 的提交，通常用于回滚到特定版本。</span><br><span class="line"></span><br><span class="line">$ git reset --hard <span class="number">602</span>fa83</span><br></pre></td></tr></table></figure>
<h3 id="切换账号执行脚本"><a href="#切换账号执行脚本" class="headerlink" title="切换账号执行脚本"></a>切换账号执行脚本</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">install_composer</span> </span>&#123;</span><br><span class="line">    # 「⚠️重点」下载 Composer 的 PHAR 文件https://learnku.com/articles/24919#topnav</span><br><span class="line">    wget https:<span class="comment">//dl.laravel-china.org/composer.phar -O /usr/local/bin/composer</span></span><br><span class="line">    # 「⚠️重点」给予该文件可执行权限</span><br><span class="line">    chmod +x /usr/local/bin/composer</span><br><span class="line">    # 配置 Packagist 国内镜像</span><br><span class="line">    sudo -H -u $&#123;WWW_USER&#125; sh -c  <span class="string">'cd ~ &amp;&amp; composer config -g repo.packagist composer https://packagist.laravel-china.org'</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="生成压缩包"><a href="#生成压缩包" class="headerlink" title="生成压缩包"></a>生成压缩包</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">对mster分支代码生成压缩包供使用者下载使用，--prefix 指定目录名</span><br><span class="line"></span><br><span class="line">git archive master --prefix=<span class="string">'hdcms/'</span> --format=zip &gt; hdcms.zip</span><br></pre></td></tr></table></figure>
<h3 id="自动部署"><a href="#自动部署" class="headerlink" title="自动部署"></a>自动部署</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">GitHub设置 WebHook</span><br><span class="line">&lt;?php</span><br><span class="line"><span class="comment">// GitHub Webhook Secret.</span></span><br><span class="line"><span class="comment">// GitHub项目 Settings/Webhooks 中的 Secret</span></span><br><span class="line">$secret = <span class="string">"houdunren"</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Path to your respostory on your server.</span></span><br><span class="line"><span class="comment">// e.g. "/var/www/respostory"</span></span><br><span class="line"><span class="comment">// 项目地址 https://www.houdunren.com/document/front/content/158?sid=1&amp;mid=2</span></span><br><span class="line">$path = <span class="string">"/www/wwwroot/xj.houdunren.com"</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Headers deliveried from GitHub</span></span><br><span class="line">$signature = $_SERVER[<span class="string">'HTTP_X_HUB_SIGNATURE'</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> ($signature) &#123;</span><br><span class="line">  $hash = <span class="string">"sha1="</span>.hash_hmac(<span class="string">'sha1'</span>, file_get_contents(<span class="string">"php://input"</span>), $secret);</span><br><span class="line">  <span class="keyword">if</span> (strcmp($signature, $hash) == <span class="number">0</span>) &#123;</span><br><span class="line">    echo shell_exec(<span class="string">"cd &#123;$path&#125; &amp;&amp; /usr/bin/git reset --hard origin/master &amp;&amp; /usr/bin/git clean -f &amp;&amp; /usr/bin/git pull 2&gt;&amp;1"</span>);</span><br><span class="line">    exit();</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">http_response_code(<span class="number">404</span>);</span><br><span class="line"></span><br><span class="line">chown -R www .</span><br><span class="line">chmod -R g+s .</span><br><span class="line">sudo -u www git pull</span><br></pre></td></tr></table></figure>
<h3 id="CONFLICT-modify-delete"><a href="#CONFLICT-modify-delete" class="headerlink" title="CONFLICT (modify/delete)"></a>CONFLICT (modify/delete)</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">$ git merge wechat_login</span><br><span class="line">CONFLICT (modify/<span class="keyword">delete</span>): Wechat.php deleted <span class="keyword">in</span> HEAD and modified <span class="keyword">in</span> wechat_login. Version wechat_login <span class="keyword">of</span> Wechat.php left <span class="keyword">in</span> tree.</span><br><span class="line">Automatic merge failed; fix conflicts and then commit the result.</span><br><span class="line"></span><br><span class="line">$ git status</span><br><span class="line">On branch master</span><br><span class="line">You have unmerged paths.</span><br><span class="line">  (fix conflicts and run <span class="string">"git commit"</span>)</span><br><span class="line">  (use <span class="string">"git merge --abort"</span> to abort the merge)</span><br><span class="line"></span><br><span class="line">Unmerged paths:</span><br><span class="line">  (use <span class="string">"git add/rm &lt;file&gt;..."</span> <span class="keyword">as</span> appropriate to mark resolution)</span><br><span class="line"></span><br><span class="line">        deleted by us:   Wechat.php</span><br><span class="line">https:<span class="comment">//www.jianshu.com/p/b08316888124</span></span><br></pre></td></tr></table></figure>
<h3 id="Already-up-to-date"><a href="#Already-up-to-date" class="headerlink" title="Already up-to-date"></a>Already up-to-date</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">先切换到master分支，再执行git checkout master</span><br><span class="line">git merge dev复制代码若合并分支时提示“Already up-to-date”在使用Git把当前分支合并到master提示“Already up-to-date”，但当前分支和 master 分支代码不同步。</span><br><span class="line">假设当前分支是：dev，主分支是：master。</span><br><span class="line">解决方法：git checkout master；</span><br><span class="line">git reset --hard dev;</span><br><span class="line">git push --force origin master</span><br><span class="line">$ git merge test</span><br><span class="line">Already up to date.</span><br><span class="line"></span><br><span class="line"> $ git status</span><br><span class="line">On branch master</span><br><span class="line">nothing to commit, working tree clean</span><br><span class="line"></span><br><span class="line"> $ git diff test app/Http/Controllers/Test.php</span><br><span class="line">diff --git a/app/Http/Controllers/Test.php b/app/Http/Controllers/Test.php</span><br><span class="line">index <span class="number">27</span>c8be83..c40f563f <span class="number">100644</span></span><br><span class="line">--- a/app/Http/Controllers/Test.php</span><br><span class="line">+++ b/app/Http/Controllers/Test.php</span><br><span class="line">@@ <span class="number">-55</span>,<span class="number">7</span> +<span class="number">55</span>,<span class="number">6</span> @@ <span class="class"><span class="keyword">class</span> <span class="title">Test</span> <span class="keyword">extends</span> <span class="title">Controller</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">-        $<span class="keyword">return</span>[<span class="string">'data'</span>] = $app ? $app[<span class="string">'result'</span>] : [];</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">     &#125;</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//juejin.im/post/5c3d5f40f265da6169177506</span></span><br></pre></td></tr></table></figure>
<h3 id="文件名大小写修改"><a href="#文件名大小写修改" class="headerlink" title="文件名大小写修改"></a>文件名大小写修改</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">先复制文件，再修改</span><br><span class="line">cp Abc.sh bbc.sh</span><br><span class="line">svn del Abc.sh</span><br><span class="line">mv bbc.sh abc.sh</span><br><span class="line">svn add abc.sh</span><br></pre></td></tr></table></figure>
<h3 id="ssh公私钥"><a href="#ssh公私钥" class="headerlink" title="ssh公私钥"></a>ssh公私钥</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">第一步，在客户端生成公钥</span><br><span class="line"></span><br><span class="line">ssh-keygen -t rsa #生成的公钥匙在 ~/.ssh/ 目录下</span><br><span class="line">第二步，把公钥上传到服务器端，登录服务器追加公钥到 authorized_keys 文件</span><br><span class="line"></span><br><span class="line">简单版</span><br><span class="line"></span><br><span class="line">ssh-copy-id -i ~<span class="regexp">/.ssh/i</span>d_rsa.pub username@ip</span><br><span class="line">复杂版</span><br><span class="line"></span><br><span class="line">scp id_rsa.pub root@ip地址:文件保存路径</span><br><span class="line">ssh root@ip #登录服务器</span><br><span class="line">cd id_rsa.pub 文件保存路径</span><br><span class="line">cat id_rsa.pub &gt;&gt; <span class="regexp">/root/</span>.ssh/authorized_keys 追加到文件中</span><br><span class="line">如果 .shh 目录或 authorized_keys 文件不存在需要自己新建</span><br><span class="line"></span><br><span class="line">第三步，修改服务器端 ssh 配置文件 /etc/ssh/sshd_config</span><br><span class="line"></span><br><span class="line">RSAAuthentication yes #开启RSA验证</span><br><span class="line">PubkeyAuthentication yes #是否使用公钥验证</span><br><span class="line">PasswordAuthentication no #禁止使用密码验证登录</span><br><span class="line">chmod 700 /root/.ssh/     #为了安全把文件修改权限，可选，部分系统新建即为 700</span><br><span class="line">chmod 600 /root/.ssh/authorized_keys  #为了安全把文件修改权限，可选，部分系统新建即为 600</span><br><span class="line">第四步，服务器端重启 ssh 服务</span><br><span class="line"></span><br><span class="line">service sshd restart #重启 sshd 服务</span><br><span class="line"></span><br><span class="line">在 .ssh 目录下新建 config 文件，内容如下</span><br><span class="line"></span><br><span class="line">Host test1           #自定义名称</span><br><span class="line">HostName ip          #服务器 ip 地址</span><br><span class="line">User nick            #用户名</span><br><span class="line">Port 22              # ssh 端口号，默认 22 可以不设置</span><br><span class="line"></span><br><span class="line">Host test2           #自定义名称</span><br><span class="line">HostName ip          #服务器 ip 地址</span><br><span class="line">User nick            #用户名</span><br><span class="line">Port 22228           # ssh 端口，自定义端口，修改为指定端口号</span><br><span class="line">连接方式</span><br><span class="line"></span><br><span class="line">ssh test1 #如果配置了公私钥就直接登录，没有的话输入密码登录 https://linux.hellocode.name/used-settings.html</span><br></pre></td></tr></table></figure>
<h3 id="Connection-reset"><a href="#Connection-reset" class="headerlink" title="Connection reset"></a>Connection reset</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">ssh: connect to host github.com port <span class="number">22</span>: Connection timed out</span><br><span class="line">fatal: Could not read <span class="keyword">from</span> remote repository.</span><br><span class="line"></span><br><span class="line">Please make sure you have the correct access rights</span><br><span class="line">and the repository exists.</span><br><span class="line"></span><br><span class="line">说明git软件无法通过ssh连接到github,有可能时防火墙或ISP设置的防火墙阻止端口<span class="number">22</span>上的ssh连接，可以用以下命令替换:</span><br><span class="line">git remote add origin-https xxx(https方式)</span><br><span class="line">git push -u origin-https master</span><br><span class="line">git pull origin-https master</span><br><span class="line"></span><br><span class="line">$ git config --local -l</span><br><span class="line">core.repositoryformatversion=<span class="number">0</span></span><br><span class="line">core.filemode=<span class="literal">false</span></span><br><span class="line">core.bare=<span class="literal">false</span></span><br><span class="line">core.logallrefupdates=<span class="literal">true</span></span><br><span class="line">core.symlinks=<span class="literal">false</span></span><br><span class="line">core.ignorecase=<span class="literal">true</span></span><br><span class="line">remote.github.url=git@sushengbuhuo.github.com:sushengbuhuo/sushengbuhuo.github.io.git</span><br><span class="line">remote.github.fetch=+refs/heads/backup:refs/remotes/github/backup</span><br><span class="line">branch.master.remote=github</span><br><span class="line">branch.master.merge=refs/heads/backup</span><br><span class="line"></span><br><span class="line">运行git config --local -e打开配置信息。</span><br><span class="line">修改其中的</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">url = git@github.com:username/repo.git</span><br><span class="line">为</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">url = https:<span class="comment">//username@github.com/username/repo.git</span></span><br><span class="line">这样就改为使用https协议了。提交什么的就OK了。</span><br></pre></td></tr></table></figure>
<h3 id="Could-not-read-from-remote-repository"><a href="#Could-not-read-from-remote-repository" class="headerlink" title="Could not read from remote repository"></a>Could not read from remote repository</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line">$ git clone git@xxx.com/app/api.git</span><br><span class="line">Cloning into <span class="string">'api'</span>...</span><br><span class="line">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</span><br><span class="line">@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @</span><br><span class="line">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</span><br><span class="line">The ECDSA host key <span class="keyword">for</span> git.staff.sina.com.cn has changed,</span><br><span class="line">and the key <span class="keyword">for</span> the corresponding IP address  </span><br><span class="line">is unknown. This could either mean that</span><br><span class="line">DNS SPOOFING is happening or the IP address <span class="keyword">for</span> the host</span><br><span class="line">and its host key have changed at the same time.</span><br><span class="line">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</span><br><span class="line">@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @</span><br><span class="line">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</span><br><span class="line">IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!</span><br><span class="line">Someone could be eavesdropping on you right now (man-<span class="keyword">in</span>-the-middle attack)!</span><br><span class="line">It is also possible that a host key has just been changed.</span><br><span class="line">The fingerprint <span class="keyword">for</span> the ECDSA key sent by the remote host is</span><br><span class="line">SHA256:q5enZT9xuv1ySs09+ .</span><br><span class="line">Please contact your system administrator.</span><br><span class="line">Add correct host key <span class="keyword">in</span> /c/Users/xxx/.ssh/known_hosts to get rid <span class="keyword">of</span> <span class="keyword">this</span> message.</span><br><span class="line">Offending ECDSA key <span class="keyword">in</span> /c/Users/xxx/.ssh/known_hosts:<span class="number">8</span></span><br><span class="line">ECDSA host key <span class="keyword">for</span> git.xxx.com has changed and you have requested strict checking.</span><br><span class="line">Host key verification failed.</span><br><span class="line">fatal: Could not read <span class="keyword">from</span> remote repository.</span><br><span class="line"></span><br><span class="line">Please make sure you have the correct access rights</span><br><span class="line">and the repository exists.</span><br><span class="line"></span><br><span class="line">删除/c/Users/xxx/.ssh/known_hosts 第<span class="number">8</span>行重新clone </span><br><span class="line">git clone git@xxx.com/app/api.git</span><br><span class="line">Cloning into <span class="string">'api'</span>...</span><br><span class="line">The authenticity <span class="keyword">of</span> host <span class="string">'git.xxx.com  '</span> can<span class="string">'t be established.</span></span><br><span class="line"><span class="string">ECDSA key fingerprint is SHA256:q5enZT9xuv1ySs09+ .</span></span><br><span class="line"><span class="string">Are you sure you want to continue connecting (yes/no)? yes</span></span><br><span class="line"><span class="string">Warning: Permanently added '</span>git.xxx.com, <span class="string">' (ECDSA) to the list of known hosts.</span></span><br><span class="line"><span class="string">remote: Enumerating objects: 63303, done.</span></span><br><span class="line"><span class="string">remote: Counting objects: 100% (63303/63303), done.</span></span><br><span class="line"><span class="string">remote: Compressing objects: 100% (19487/19487), done.</span></span><br><span class="line"><span class="string">remote: Total 63303 (delta 42781), reused 62710 (delta 42523)</span></span><br><span class="line"><span class="string">Receiving objects: 100% (63303/63303), 23.86 MiB | 14.71 MiB/s, done.</span></span><br><span class="line"><span class="string">Resolving deltas: 100% (42781/42781), done.</span></span><br><span class="line"><span class="string">Checking out files: 100% (9761/9761), done.</span></span><br></pre></td></tr></table></figure>
<h3 id="Git-优雅的撤销中间某次提交"><a href="#Git-优雅的撤销中间某次提交" class="headerlink" title="Git 优雅的撤销中间某次提交"></a>Git 优雅的撤销中间某次提交</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">git revert <span class="number">100047</span>dcc -m <span class="number">1</span></span><br><span class="line">参数 -m 就是指定要撤销的那个提价，从左往右，从 <span class="number">1</span> 开始数；也就是我撤销的是 <span class="number">0099</span>aca7。</span><br><span class="line">接着其把代码冲突，然后我就解决冲突，保留主分支的代码，去掉那个人的代码。</span><br><span class="line">git push</span><br><span class="line"></span><br><span class="line"><span class="number">1</span>，首先git log查看提交记录，找到出错的前一笔提交的commit_id</span><br><span class="line"></span><br><span class="line"><span class="number">2</span>，用命令git rebase -i commit_id ,查找提交记录</span><br><span class="line"></span><br><span class="line"><span class="number">3</span>，将出错那笔提交的pick改为drop</span><br><span class="line"></span><br><span class="line"><span class="number">4</span>，Esc，:wq</span><br><span class="line"></span><br><span class="line">1、git reset --hard 1d7444 #回退到出错版本前一个commit</span><br><span class="line"></span><br><span class="line">2、git cherry-pick 626335 #将某次commit的更改应用到当前版本(将出错 cmmit 之后别人提交的代码合并到当前正常代码分支上)</span><br><span class="line"></span><br><span class="line">3、git push origin HEAD --force  #强制提交</span><br><span class="line">https:<span class="comment">//learnku.com/articles/31705</span></span><br></pre></td></tr></table></figure>
<h3 id="git原理"><a href="#git原理" class="headerlink" title="git原理"></a>git原理</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">创建 blob 对象：</span><br><span class="line"></span><br><span class="line">$ echo <span class="string">'test content'</span> | git hash-object -w --stdin</span><br><span class="line"></span><br><span class="line">-w 表示存储对象。</span><br><span class="line"></span><br><span class="line">d670460b4b4aece5915caf5c68d12f560a9fe3e</span><br><span class="line"></span><br><span class="line">返回一个长度为 <span class="number">40</span> 字符的校验和，为对象名。校验和是一个 SHA<span class="number">-1</span> 哈希值，由对象数据和一个 header 一起做 SHA<span class="number">-1</span> 校验运算而成。</span><br><span class="line"></span><br><span class="line">读取 blod 对象</span><br><span class="line"></span><br><span class="line">$ git cat-file -p d670460b4b4aece5915caf5c68d12f560a9fe3e</span><br><span class="line"></span><br><span class="line">test content</span><br><span class="line"></span><br><span class="line">-p Pretty-print the contents <span class="keyword">of</span> object based on its type.</span><br><span class="line"></span><br><span class="line">-t 输出对象类型</span><br><span class="line"></span><br><span class="line">blob</span><br><span class="line">HEAD 引用</span><br><span class="line"></span><br><span class="line">用途：记录当前分支所在的分支引用</span><br><span class="line"></span><br><span class="line">存储当前分支的引用的引用，是一个符号引用，不像普通引用包含一个 SHA<span class="number">-1</span> 值。</span><br><span class="line"></span><br><span class="line">$ cat .git/HEAD</span><br><span class="line"></span><br><span class="line">ref: refs/heads/test</span><br><span class="line"> cat .git/refs/heads/master</span><br><span class="line"><span class="number">4</span>b8c160d38e4befa3bc515f12208583dd4e8814f</span><br><span class="line"></span><br><span class="line">$ cat .git/refs/remotes/origin/master</span><br><span class="line"></span><br><span class="line"><span class="number">4</span>b8c160d38e4befa3bc515f12208583dd4e8814f</span><br><span class="line"></span><br><span class="line">git cat-file -p <span class="number">4</span>b8c160d38e4befa3bc515f12208583dd4e8814f</span><br><span class="line"></span><br><span class="line">tree <span class="number">40</span>db0fc4e10857c0a774365c799ffd7e2fe4c052</span><br><span class="line">parent cb65f329f7928a39e801af5151539246a70dfea6</span><br><span class="line">parent ae4107d8e7eb6dec926f2488c70dab23a06bc9d8</span><br><span class="line">author <span class="number">666</span> <span class="number">1565317494</span> +<span class="number">0800</span></span><br><span class="line">committer <span class="number">66</span> <span class="number">1565317494</span> +<span class="number">0800</span></span><br><span class="line"></span><br><span class="line">Merge branch <span class="string">'feature/test'</span></span><br><span class="line">https:<span class="comment">//learnku.com/articles/32272</span></span><br></pre></td></tr></table></figure>
<h3 id="Git-获取指定文件"><a href="#Git-获取指定文件" class="headerlink" title="Git 获取指定文件"></a>Git 获取指定文件</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//me.jinchuang.org/archives/145.html</span></span><br><span class="line">具体实现如下：</span><br><span class="line">$mkdir project_folder</span><br><span class="line">$cd project_folder</span><br><span class="line">$git init</span><br><span class="line">$git remote add -f origin &lt;url&gt;</span><br><span class="line">上面的代码会帮助你创建一个空的本地仓库，同时将远程Git Server URL加入到Git Config文件中。</span><br><span class="line">接下来，我们在Config中允许使用Sparse Checkout模式：</span><br><span class="line">$git config core.sparsecheckout <span class="literal">true</span> </span><br><span class="line">接下来你需要告诉Git哪些文件或者文件夹是你真正想Check Out的，你可以将它们作为一个列表保存在.git/info/sparse-checkout文件中。</span><br><span class="line">例如：</span><br><span class="line">$echo “libs” &gt;&gt; .git/info/sparse-checkout </span><br><span class="line">$echo “apps/register.go” &gt;&gt; .git/info/sparse-checkout </span><br><span class="line">$echo “resource/css” &gt;&gt; .git/info/sparse-checkout </span><br><span class="line">最后，你只要以正常方式从你想要的分支中将你的项目拉下来就可以了：</span><br><span class="line">$git pull origin master</span><br></pre></td></tr></table></figure>
<h3 id="Git-实现-Laravel-项目的自动化部署"><a href="#Git-实现-Laravel-项目的自动化部署" class="headerlink" title="Git 实现 Laravel 项目的自动化部署"></a>Git 实现 Laravel 项目的自动化部署</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"># 创建一个名叫jouzeyu的用户</span><br><span class="line">adduser jouzeyu</span><br><span class="line">#在根目录下的 home 文件夹下创建一个git文件夹</span><br><span class="line">mkdir /home/git </span><br><span class="line">#切换到创建好的git文件夹</span><br><span class="line">cd /home/git</span><br><span class="line">#创建 .ssh文件夹，里面主要用来放公钥</span><br><span class="line">mkdir .ssh</span><br><span class="line">#切换到.ssh文件夹并创建authorized_keys文件</span><br><span class="line">cd .ssh</span><br><span class="line">touch authorized_keys</span><br><span class="line"></span><br><span class="line">使用 cat ~<span class="regexp">/.ssh/i</span>d_rsa.pub 命令可以获取公钥，复制它，使用 vi 或者 vim 命令把它粘贴到我们之前创建的 authorized_keys 文件中，使用:wq 保存</span><br><span class="line"></span><br><span class="line">mkdir /www/wwwroot/git</span><br><span class="line">cd /www/wwwroot/git</span><br><span class="line">初始化仓库：</span><br><span class="line"></span><br><span class="line">#初始化一个裸仓库（强烈建议）</span><br><span class="line">git init --bare website.git</span><br><span class="line">#配置仓库的权限，让我们之前创建好的git用户jouzeyu能读写</span><br><span class="line">chown -R git:git website.git</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#创建我服务器上的项目目录test</span><br><span class="line">mkdir /www/wwwroot/test</span><br><span class="line">#克隆仓库</span><br><span class="line">git clone /www/wwwroot/git/website.git</span><br><span class="line">#设置权限</span><br><span class="line">chown -R git website</span><br><span class="line"></span><br><span class="line"># 通过ip地址从配置好的线上仓库拉取下来</span><br><span class="line">git clone git@<span class="number">47.97</span><span class="number">.121</span>.XXX:<span class="regexp">/www/</span>wwwroot/git/website.git</span><br><span class="line"># 如果有配置域名的话也可以通过域名拉取</span><br><span class="line">git clone git@www.XXX.XXX:<span class="regexp">/www/</span>wwwroot/git/website.git</span><br><span class="line"></span><br><span class="line"># 打开刚才克隆下来的本地仓库</span><br><span class="line">cd website</span><br><span class="line"># 创建README.md文件</span><br><span class="line">touch README.md</span><br><span class="line">git add .</span><br><span class="line">git commit -m<span class="string">"创建README.md文件"</span></span><br><span class="line">git push</span><br><span class="line"></span><br><span class="line">#切换到这个目录</span><br><span class="line">cd /www/wwwroot/git/website.git/hooks</span><br><span class="line"># 生成post-receive文件</span><br><span class="line">touch post-receive</span><br><span class="line"># 使用vim编辑</span><br><span class="line">vim post-receive</span><br><span class="line"></span><br><span class="line"><span class="meta">#!/bin/sh</span></span><br><span class="line"># 打印输出</span><br><span class="line">echo <span class="string">'======上传代码到服务器======'</span></span><br><span class="line"># 打开线上项目文件夹</span><br><span class="line">cd /www/wwwroot/test/website</span><br><span class="line"># 这个很重要，如果不取消的话将不能在cd的路径上进行git操作</span><br><span class="line">unset GIT_DIR</span><br><span class="line">git pull origin master</span><br><span class="line"># 自动编译vue项目,如有需要请去掉前面的#号</span><br><span class="line"># npm run build</span><br><span class="line"># 自动更新composer（我暂时没试过）</span><br><span class="line"># composer update</span><br><span class="line">echo $(date) &gt;&gt; hook.log</span><br><span class="line">echo <span class="string">'======代码更新完成======'</span></span><br><span class="line"></span><br><span class="line">chmod +x post-receive</span><br><span class="line">https:<span class="comment">//learnku.com/articles/33689</span></span><br></pre></td></tr></table></figure>
<h3 id="gitee-和-GitHub-的-webhook-的使用"><a href="#gitee-和-GitHub-的-webhook-的使用" class="headerlink" title="gitee 和 GitHub 的 webhook 的使用"></a>gitee 和 GitHub 的 webhook 的使用</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//访问秘钥</span></span><br><span class="line">$keySecret = <span class="string">'^!@KVzPZ^DaRNA7R53353%7aEAfsfdOptH7b%0i5'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//需要更新的项目目录</span></span><br><span class="line">$wwwRoot = [</span><br><span class="line">    <span class="string">'/www/wwwroot/test1'</span>,</span><br><span class="line">    <span class="string">'/www/wwwroot/test2'</span>,</span><br><span class="line">];</span><br><span class="line"></span><br><span class="line"><span class="comment">//保存运行脚本的日志</span></span><br><span class="line">$logFile = <span class="string">'log/layuimini-githook.log'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//git执行命令</span></span><br><span class="line">$gitCommand = <span class="string">'git pull'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 判断是否开启秘钥认证(已实现gitee和github)</span></span><br><span class="line"><span class="keyword">if</span> (isset($keySecret) &amp;&amp; !empty($keySecret)) &#123;</span><br><span class="line">    list($headers, $gitType) = [[], <span class="literal">null</span>];</span><br><span class="line">    foreach ($_SERVER <span class="keyword">as</span> $key =&gt; $value) &#123;</span><br><span class="line">        <span class="string">'HTTP_'</span> == substr($key, <span class="number">0</span>, <span class="number">5</span>) &amp;&amp; $headers[str_replace(<span class="string">'_'</span>, <span class="string">'-'</span>, substr($key, <span class="number">5</span>))] = $value;</span><br><span class="line">        <span class="keyword">if</span> (empty($gitType) &amp;&amp; strpos($key, <span class="string">'GITEE'</span>) !== <span class="literal">false</span>) &#123;</span><br><span class="line">            $gitType = <span class="string">'GITEE'</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (empty($gitType) &amp;&amp; strpos($key, <span class="string">'GITHUB'</span>) !== <span class="literal">false</span>) &#123;</span><br><span class="line">            $gitType = <span class="string">'GITHUB'</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> ($gitType == <span class="string">'GITEE'</span>) &#123;</span><br><span class="line">        <span class="keyword">if</span> (!isset($headers[<span class="string">'X-GITEE-TOKEN'</span>]) || $headers[<span class="string">'X-GITEE-TOKEN'</span>] != $keySecret) &#123;</span><br><span class="line">            die(<span class="string">'GITEE - 请求失败，秘钥有误'</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; elseif ($gitType == <span class="string">'GITHUB'</span>) &#123;</span><br><span class="line">        $json_content = file_get_contents(<span class="string">'php://input'</span>);</span><br><span class="line">        $signature = <span class="string">"sha1="</span> . hash_hmac(<span class="string">'sha1'</span>, $json_content, $keySecret);</span><br><span class="line">        <span class="keyword">if</span> ($signature != $headers[<span class="string">'X-HUB-SIGNATURE'</span>]) &#123;</span><br><span class="line">            die(<span class="string">'GITHUB - 请求失败，秘钥有误'</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        die(<span class="string">'请求错误，未知git类型'</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">!is_array($wwwRoot) &amp;&amp; $wwwRoot = [$wwwRoot];</span><br><span class="line">foreach ($wwwRoot <span class="keyword">as</span> $vo) &#123;</span><br><span class="line">    $shell = sprintf(<span class="string">"cd %s &amp;&amp; git pull 2&gt;&amp;1"</span>, $vo);</span><br><span class="line">    $output = shell_exec($shell);</span><br><span class="line">    $log = sprintf(<span class="string">"[%s] %s \n"</span>, date(<span class="string">'Y-m-d H:i:s'</span>, time()) . <span class="string">' - '</span> . $vo, $output);</span><br><span class="line">    echo $log;</span><br><span class="line">    file_put_contents($logFile, $log, FILE_APPEND);</span><br><span class="line">&#125;</span><br><span class="line">修改项目目录权限 chown -R www:www 项目路径</span><br></pre></td></tr></table></figure>
<h3 id="Forestry-管理基于-GitHub-的图床"><a href="#Forestry-管理基于-GitHub-的图床" class="headerlink" title="Forestry 管理基于 GitHub 的图床"></a>Forestry 管理基于 GitHub 的图床</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">免费提供静态博客管理功能，使你的博客拥有 CMS 般的体验。</span><br><span class="line">你可以很轻松地编写、修改和发布博客，包括图片与文件，而不需要手动去编译上传，Forestry 已经为你自动处理了</span><br><span class="line">github登录https:<span class="comment">//forestry.io/</span></span><br><span class="line"></span><br><span class="line">授权对应的GitHub库</span><br><span class="line"></span><br><span class="line">修改时区</span><br><span class="line"></span><br><span class="line">Settings &gt;&gt; General &gt;&gt; TIMEZONE，选择 (GMT+<span class="number">08</span>:<span class="number">00</span>) Beijing，保存 Save settings</span><br><span class="line"></span><br><span class="line">修改上传规则</span><br><span class="line"></span><br><span class="line">Settings &gt;&gt; Media &gt;&gt; UPLOAD DIRECTORY 改为空</span><br><span class="line">Settings &gt;&gt; Media &gt;&gt; PUBLIC PATH 改为空</span><br><span class="line">Settings &gt;&gt; Media &gt;&gt; FILE PATH 改为 :year::month::day:<span class="regexp">/:filename:</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">本地上传文件 在GitHub可以看到 </span></span><br><span class="line"><span class="regexp"> 图片地址 https:/</span><span class="regexp">/cdn.jsdelivr.net/g</span>h/sushengbuhuo/pics@master/<span class="number">20191022</span>/钟楚红.jpg</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//gleehub.com/other/shi-yong-forestry-guan-li-ji-yu-github-de-tu-chuang.html</span></span><br><span class="line">使用jsDelivr加速Github仓库的图片作为博客的图床 https:<span class="comment">//tingtas.com/posts/4341d485/#前言</span></span><br></pre></td></tr></table></figure>
<h3 id="删除git历史"><a href="#删除git历史" class="headerlink" title="删除git历史"></a>删除git历史</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">git checkout --orphan <span class="keyword">new</span></span><br><span class="line">git add -A</span><br><span class="line">git commit -m <span class="string">"init"</span></span><br><span class="line">    git branch -D master</span><br><span class="line"></span><br><span class="line">git branch -m <span class="keyword">new</span> master</span><br><span class="line">git push --set-upstream origin master -f</span><br><span class="line">https:<span class="comment">//juejin.im/post/5be995c25188250fa8358f9d</span></span><br></pre></td></tr></table></figure>
<p><a href="https://learnku.com/articles/30215" target="_blank" rel="noopener">Linux 环境下 Git 服务器的搭建</a></p>
<p><a href="https://github.com/letseeqiji/git-helper/blob/master/README.md" target="_blank" rel="noopener">Git 命令行辅助脚本工具</a></p>
<p><a href="http://wiki.jikexueyuan.com/project/github-pages-basics/" target="_blank" rel="noopener">GitHub Pages 指南极客学院</a></p>
<p><a href="https://www.boatsky.com/blog/12" target="_blank" rel="noopener">git简化笔记</a></p>
<p><a href="http://pinkyjie.com/2014/08/10/git-notes-part-3/" target="_blank" rel="noopener">Git笔记(三)——[cherry-pick, merge, rebase]</a></p>
<p><a href="http://cs-cjl.com/2014/05/06/learn_git_with_me_12" target="_blank" rel="noopener">跟我一起学Git(十二) 合并项目 </a></p>
<p><a href="https://zhuanlan.zhihu.com/p/34197548" target="_blank" rel="noopener">GIT使用rebase和merge的正确姿势</a></p>
<p><a href="https://www.playpi.org/2019030601.html" target="_blank" rel="noopener">Github 的 WebHooks 实现代码自动更新</a></p>
<p><a href="https://sourcegraph.com/welcome" target="_blank" rel="noopener">GitHub搜索</a></p>
<p><a href="https://github.com/hotvulcan/Thanos.sh" target="_blank" rel="noopener">随机删文件</a></p>
<p><a href="https://github.com/LCTT/Grank" target="_blank" rel="noopener">Github 项目活跃度分析工具</a></p>
<p><a href="https://git-issues.now.sh/" target="_blank" rel="noopener">浏览 GitHub 问题和提取请求的方法</a></p>
<p><a href="https://github.com/happypeter/gitbeijing" target="_blank" rel="noopener">github 图解教程</a></p>
<p><a href="https://zmcdbp.com/install-gogs-in-windows/" target="_blank" rel="noopener">在Windows安装Gogs</a></p>
<p><a href="https://blog.yiranzai.cn/posts/48628/" target="_blank" rel="noopener">svn安装和使用总结</a></p>
<p><a href="http://whatthecommit.com/" target="_blank" rel="noopener">随机生成 Git commit git commit -m $(curl -s http://whatthecommit.com/index.txt)
</a></p>
<p><a href="https://blog.yiranzai.cn/posts/48629/" target="_blank" rel="noopener">CentOS 7 | Firewall防火墙使用总结</a></p>
<p><a href="https://blog.yiranzai.cn/posts/26850/" target="_blank" rel="noopener">基于Gitea打造一个属于你自己的代码托管平台</a></p>
<p><a href="https://blog.yiranzai.cn/posts/26847/" target="_blank" rel="noopener">基于 Gitea+Drone CI+Vault 打造属于自己的CI/CD工作流</a></p>
<p><a href="https://learngitbranching.js.org/" target="_blank" rel="noopener">Git 练习场–直观形象又好玩</a></p>
<p><a href="http://fanqieto.top/2018/02/27/linux%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5/" target="_blank" rel="noopener">linux从入门到实践</a></p>
<p><a href="http://fanqieto.top/2017/11/29/nginx%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E5%AE%9E%E8%B7%B5/" target="_blank" rel="noopener">nginx从入门到实践</a></p>
<p><a href="https://www.cnblogs.com/dee0912/p/5815267.html" target="_blank" rel="noopener">在 Linux 下搭建 Git 服务器</a></p>
<p><a href="https://mp.weixin.qq.com/s/sXQ3L-CWvcEW-l14JYW8uA" target="_blank" rel="noopener">学习git</a></p>
<p><a href="https://www.kancloud.cn/yangweijie/yang_book/30713" target="_blank" rel="noopener">学好英语，走向国际</a></p>
<p><a href="https://learnku.com/articles/24382" target="_blank" rel="noopener">Mac/Linux 安装中文版 man 帮助命令</a></p>
<p><a href="https://github.com/guanguans/notes" target="_blank" rel="noopener">PHP、Git、Shell等笔记</a></p>
<p><a href="https://learnku.com/articles/24360" target="_blank" rel="noopener">netstat 命令查看连接数判断攻击</a></p>
<p><a href="http://coderlt.coding.me/2016/05/01/build-github-wiki/" target="_blank" rel="noopener">在Github上建立自己的Wiki</a></p>
<p><a href="https://tonydeng.github.io/2015/07/08/how-to-undo-almost-anything-with-git/" target="_blank" rel="noopener">Git的各种Undo技巧</a></p>
<p><a href="http://www.syyong.com/linux/PHPer-need-to-master-the-common-linux-commands.html" target="_blank" rel="noopener">PHPer 要掌握的常用 linux 命令</a></p>
<p><a href="https://learnku.com/articles/33729" target="_blank" rel="noopener">GitLab 安装、管理、运维</a></p>
<p><a href="https://github.dev/" target="_blank" rel="noopener">个人网站生成器工具</a></p>
<p><a href="https://github.com/royeo/git-checkout-branch" target="_blank" rel="noopener">切换git分支</a></p>
<p><a href="https://learnku.com/articles/33689" target="_blank" rel="noopener">Git 实现 Laravel 项目的自动化部署</a></p>
<p><a href="https://blog.csdn.net/qq_15037231/article/details/77743062" target="_blank" rel="noopener">Linux bash总结</a></p>
<p><a href="https://github.com/GitHubDaily/GitHubDaily" target="_blank" rel="noopener">GitHubDaily 分享内容定期整理与分类</a></p>
<p><a href="https://github.com/billryan/algorithm-exercise" target="_blank" rel="noopener">数据结构与算法/leetcode/lintcode题解</a></p>
<p><a href="https://github.com/dipakkr/A-to-Z-Resources-for-Students" target="_blank" rel="noopener">来自不同开发人员为大学生收集整理的一系列资源</a></p>
<p><a href="https://github.com/24OI/OI-wiki/" target="_blank" rel="noopener">整合了编程竞赛有趣又实用的知识站点</a></p>
<p><a href="https://hackertarget.com/ssh-examples-tunnels" target="_blank" rel="noopener">ssh example</a></p>
<p><a href="https://github.com/xingshaocheng/architect-awesome/blob/master/README.md" target="_blank" rel="noopener">《后端架构师技术图谱》</a></p>
<p><a href="https://laravel-china.org/articles/22068?#reply77626" target="_blank" rel="noopener">Git 的奇技淫巧</a></p>
<p><a href="https://laravel-china.org/articles/22107?#reply77627" target="_blank" rel="noopener">Linux 笔记分享二十（终章）：网络命令</a></p>
<p><a href="https://coffeephp.com/articles/3" target="_blank" rel="noopener">搭建Git服务器 </a></p>
<p><a href="https://www.goozp.com/article/83.html" target="_blank" rel="noopener">入门 Linux 之 从命令行开始</a></p>
<p><a href="https://www.fanhaobai.com/2016/05/recover-file.html" target="_blank" rel="noopener">Linux下恢复误删除的文件</a></p>
<p><a href="https://www.goozp.com/article/86.html" target="_blank" rel="noopener">Linux 下工作必须会的命令清单</a></p>
<p><a href="https://juejin.im/post/5c22056551882518fc5fe294?utm_source=gold_browser_extension#heading-40" target="_blank" rel="noopener">中日合拍的《Git游记》即将正式开机</a></p>
<p><a href="https://github.com/pomber/git-history" target="_blank" rel="noopener">查看 Git 文件变动历史</a></p>
<p><a href="https://segmentfault.com/a/1190000016732183" target="_blank" rel="noopener">Git的奇技淫巧</a></p>
<p><a href="https://michael728.github.io/2018/09/08/tools-gitbook-hackpythonista-notebook/" target="_blank" rel="noopener">使用GitBook+Github编写文档书籍</a></p>
<p><a href="https://backlog.com/git-tutorial/cn/" target="_blank" rel="noopener">猴子都能懂得git</a></p>
<p><a href="https://gleehub.com/program/git-commit-emoji-shi-yong-zhi-nan.html" target="_blank" rel="noopener">Git commit emoji </a></p>
<p><a href="https://skyao.io/learning-git/" target="_blank" rel="noopener">git 学习笔记</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/git/" rel="tag"># git</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/01/08/laravel-cache-facade/" rel="next" title="laravel cache facade">
                <i class="fa fa-chevron-left"></i> laravel cache facade
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/01/11/数据分析平台grafana/" rel="prev" title="数据分析平台grafana">
                数据分析平台grafana <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
          <div class="comments" id="comments">
             <div id="gitment-container"></div>
         </div>
  




        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">苏生不惑</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">382</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">37</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/sushengbuhuo" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mysusheng@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://plus.google.com/mysusheng" target="_blank" title="Google">
                      
                        <i class="fa fa-fw fa-google"></i>Google</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://v2ex.com/" title="v2ex" target="_blank">v2ex</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.fanhaobai.com/" title="fanhaobai" target="_blank">fanhaobai</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="yuanxuxu" target="_blank">yuanxuxu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.snail-c.cn/article" title="snail-c" target="_blank">snail-c</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://showcj.com/archives" title="showcj" target="_blank">showcj</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://vultr.aicnm.com/%E6%9C%80%E6%96%B0Vultr%E6%B3%A8%E5%86%8C%E5%8F%8AVPS%E8%B4%AD%E4%B9%B0%E5%9B%BE%E6%96%87%E6%95%99%E7%A8%8B/" title="vultr" target="_blank">vultr</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lucissfer.com/" title="lucissfer" target="_blank">lucissfer</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.csdn.net/fdipzone/article/details/79352685" title="傲雪星枫" target="_blank">傲雪星枫</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yoby123.cn/index.php/category/default/" title="小白的分享" target="_blank">小白的分享</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/p/5819995.html" title="PHP攻城狮" target="_blank">PHP攻城狮</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.jiaojie.site/" title="php" target="_blank">php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://sphard.com/archives/" title="sphard" target="_blank">sphard</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="LNMP技术栈笔记" target="_blank">LNMP技术栈笔记</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.coding10.com/" title="学习 Laravel" target="_blank">学习 Laravel</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://shuwoom.com/?page_id=929" title="区块链学习指南" target="_blank">区块链学习指南</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://greenlightt.github.io/archives/" title="greenlightt" target="_blank">greenlightt</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.0php.net/archives/" title="0php" target="_blank">0php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.fordba.com/category/mysql" title="mysql" target="_blank">mysql</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.itcodemonkey.com/" title="程序员" target="_blank">程序员</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yanshuo.me/r/v2ex" title="言说" target="_blank">言说</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.timiguo.com/archive.html" title="提米果的博客" target="_blank">提米果的博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://phpartisan.cn/news/112.html" title="phpartisan" target="_blank">phpartisan</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/" title="飞鸿影" target="_blank">飞鸿影</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.54php.cn/" title="54php" target="_blank">54php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lazyman.vip/" title="营销" target="_blank">营销</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.njphper.com/archives/" title="做人呢最重要的就是开心" target="_blank">做人呢最重要的就是开心</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.h57.pw/" title="php 初心者" target="_blank">php 初心者</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#linux"><span class="nav-number">1.</span> <span class="nav-text">linux</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#回到远程仓库的状态"><span class="nav-number">2.</span> <span class="nav-text">回到远程仓库的状态</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#重设第一个commit"><span class="nav-number">3.</span> <span class="nav-text">重设第一个commit</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除已经合并到master的分支"><span class="nav-number">4.</span> <span class="nav-text">删除已经合并到master的分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#展示本地分支关联远程仓库的情况"><span class="nav-number">5.</span> <span class="nav-text">展示本地分支关联远程仓库的情况</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#关联远程分支"><span class="nav-number">6.</span> <span class="nav-text">关联远程分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#列出所有远程分支"><span class="nav-number">7.</span> <span class="nav-text">列出所有远程分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#列出本地和远程分支"><span class="nav-number">8.</span> <span class="nav-text">列出本地和远程分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#从远程分支中创建并切换到本地分支"><span class="nav-number">9.</span> <span class="nav-text">从远程分支中创建并切换到本地分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除远程分支"><span class="nav-number">10.</span> <span class="nav-text">删除远程分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#重命名本地分支"><span class="nav-number">11.</span> <span class="nav-text">重命名本地分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#切回到某个标签"><span class="nav-number">12.</span> <span class="nav-text">切回到某个标签</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#放弃工作区的修改"><span class="nav-number">13.</span> <span class="nav-text">放弃工作区的修改</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改远程仓库的url"><span class="nav-number">14.</span> <span class="nav-text">修改远程仓库的url</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查看两个星期内的改动"><span class="nav-number">15.</span> <span class="nav-text">查看两个星期内的改动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#展示简化的commit历史"><span class="nav-number">16.</span> <span class="nav-text">展示简化的commit历史</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#展示任意分支某一文件的内容"><span class="nav-number">17.</span> <span class="nav-text">展示任意分支某一文件的内容</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#clone下来指定的单一分支"><span class="nav-number">18.</span> <span class="nav-text">clone下来指定的单一分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#忽略某个文件的改动"><span class="nav-number">19.</span> <span class="nav-text">忽略某个文件的改动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在commit-log中查找相关内容"><span class="nav-number">20.</span> <span class="nav-text">在commit log中查找相关内容</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#搭建Git服务器"><span class="nav-number">21.</span> <span class="nav-text">搭建Git服务器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查看定时任务日志"><span class="nav-number">22.</span> <span class="nav-text">查看定时任务日志</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#GitHub-API-limit"><span class="nav-number">23.</span> <span class="nav-text">GitHub API limit</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在Git中添加忽略文件"><span class="nav-number">24.</span> <span class="nav-text">在Git中添加忽略文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#一键提交脚本"><span class="nav-number">25.</span> <span class="nav-text">一键提交脚本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#免密登录"><span class="nav-number">26.</span> <span class="nav-text">免密登录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#最近24小时修改过的文件"><span class="nav-number">27.</span> <span class="nav-text">最近24小时修改过的文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改-hostname"><span class="nav-number">28.</span> <span class="nav-text">修改 hostname</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查找文件"><span class="nav-number">29.</span> <span class="nav-text">查找文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ssh"><span class="nav-number">30.</span> <span class="nav-text">ssh</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#scp"><span class="nav-number">31.</span> <span class="nav-text">scp</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#netstat-命令查看连接数判断攻击"><span class="nav-number">32.</span> <span class="nav-text">netstat 命令查看连接数判断攻击</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Linux-相关信息"><span class="nav-number">33.</span> <span class="nav-text">Linux 相关信息</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#反向代理以访问-Gist"><span class="nav-number">34.</span> <span class="nav-text">反向代理以访问 Gist</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#文件名大小写有问题"><span class="nav-number">35.</span> <span class="nav-text">文件名大小写有问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#paste-命令支持输入多个文件"><span class="nav-number">36.</span> <span class="nav-text">paste 命令支持输入多个文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Git-webhook"><span class="nav-number">37.</span> <span class="nav-text">Git webhook</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除某个文件的所有历史记录"><span class="nav-number">38.</span> <span class="nav-text">删除某个文件的所有历史记录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#批量kill进程"><span class="nav-number">39.</span> <span class="nav-text">批量kill进程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#nginx日志按日期切割并保留最近七天的日志"><span class="nav-number">40.</span> <span class="nav-text">nginx日志按日期切割并保留最近七天的日志</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#检测端口是否打开"><span class="nav-number">41.</span> <span class="nav-text">检测端口是否打开</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Composer-设置忽略版本匹配"><span class="nav-number">42.</span> <span class="nav-text">Composer 设置忽略版本匹配</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#linux-1"><span class="nav-number">43.</span> <span class="nav-text">linux</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#深入-Nginx-之配置篇"><span class="nav-number">44.</span> <span class="nav-text">深入 Nginx 之配置篇</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#nginx日志中提取5分钟内访问状态非200的记录"><span class="nav-number">45.</span> <span class="nav-text">nginx日志中提取5分钟内访问状态非200的记录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#golang入门"><span class="nav-number">46.</span> <span class="nav-text">golang入门</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#linux-chmod"><span class="nav-number">47.</span> <span class="nav-text">linux chmod</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#nginx-配置"><span class="nav-number">48.</span> <span class="nav-text">nginx 配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#svn搭建"><span class="nav-number">49.</span> <span class="nav-text">svn搭建</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Git-钩子检查-PHP-语法和代码规范"><span class="nav-number">50.</span> <span class="nav-text">Git 钩子检查 PHP 语法和代码规范</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#带宽被打满"><span class="nav-number">51.</span> <span class="nav-text">带宽被打满</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#你可能会忽略的-Git-提交规范"><span class="nav-number">52.</span> <span class="nav-text">你可能会忽略的 Git 提交规范</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-pull或git-checkout-后保持权限不变"><span class="nav-number">53.</span> <span class="nav-text">git pull或git checkout 后保持权限不变</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Git-仓库迁移至其他服务器并实现-hooks-自动化部署"><span class="nav-number">54.</span> <span class="nav-text">Git 仓库迁移至其他服务器并实现 hooks 自动化部署</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#更新与回滚"><span class="nav-number">55.</span> <span class="nav-text">更新与回滚</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#切换账号执行脚本"><span class="nav-number">56.</span> <span class="nav-text">切换账号执行脚本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#生成压缩包"><span class="nav-number">57.</span> <span class="nav-text">生成压缩包</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#自动部署"><span class="nav-number">58.</span> <span class="nav-text">自动部署</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#CONFLICT-modify-delete"><span class="nav-number">59.</span> <span class="nav-text">CONFLICT (modify/delete)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Already-up-to-date"><span class="nav-number">60.</span> <span class="nav-text">Already up-to-date</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#文件名大小写修改"><span class="nav-number">61.</span> <span class="nav-text">文件名大小写修改</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ssh公私钥"><span class="nav-number">62.</span> <span class="nav-text">ssh公私钥</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Connection-reset"><span class="nav-number">63.</span> <span class="nav-text">Connection reset</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Could-not-read-from-remote-repository"><span class="nav-number">64.</span> <span class="nav-text">Could not read from remote repository</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Git-优雅的撤销中间某次提交"><span class="nav-number">65.</span> <span class="nav-text">Git 优雅的撤销中间某次提交</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git原理"><span class="nav-number">66.</span> <span class="nav-text">git原理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Git-获取指定文件"><span class="nav-number">67.</span> <span class="nav-text">Git 获取指定文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Git-实现-Laravel-项目的自动化部署"><span class="nav-number">68.</span> <span class="nav-text">Git 实现 Laravel 项目的自动化部署</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#gitee-和-GitHub-的-webhook-的使用"><span class="nav-number">69.</span> <span class="nav-text">gitee 和 GitHub 的 webhook 的使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Forestry-管理基于-GitHub-的图床"><span class="nav-number">70.</span> <span class="nav-text">Forestry 管理基于 GitHub 的图床</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除git历史"><span class="nav-number">71.</span> <span class="nav-text">删除git历史</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">苏生不惑</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>



<div>
<span id="showDays"></span>

</div>

<span id="busuanzi_container_site_pv">
   总访问量:<span id="busuanzi_value_site_pv"></span>次
</span>



  <span class="post-meta-divider">|</span>



<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共773.8k字</span>
</div>
<script>
var birthDay = new Date("11/20/2018");
var now = new Date();
var duration = now.getTime() - birthDay.getTime();
var total= Math.floor(duration / (1000 * 60 * 60 * 24));
document.getElementById("showDays").innerHTML = "本站已运行 "+total+" 天";
</script>

        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  











<script type="text/javascript">
    (function() {
        // 匿名函数，防止污染全局变量
        var utterances = document.createElement('script');
        utterances.type = 'text/javascript';
        utterances.async = true;
        utterances.setAttribute('issue-term','0')
        utterances.setAttribute('theme','')
        utterances.setAttribute('repo','sushengbuhuo/laravel_ioc_demo')
        utterances.crossorigin = 'anonymous';
        utterances.src = 'https://utteranc.es/client.js';
        // content 是要插入评论的地方
        document.getElementById('gitment-container').appendChild(utterances);
    })();
</script>


  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

  
<script>
  ((window.gitter = {}).chat = {}).options = {
    //room替换成自己的聊天室名称即可，room的名称规则是：username/roomname
    room: 'sushengbuhuo-chat/mychat'
  };
</script>
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>

</body>
</html>
